gpt4 book ai didi

c# - 使用 c# 从 Panasonic PBX 捕获数据

转载 作者:行者123 更新时间:2023-12-03 12:05:28 26 4
gpt4 key购买 nike

我编写了以下代码来从 Panasonic PBX(KX-TDE 100/200) 捕获数据并将其写入文件。
当我尝试运行以下代码时,它在任务管理器中显示“无响应”。
我也尝试调试可能是问题所在。该行

套接字套接字 = listener.Accept(); 将在调试时被击中,然后显示“无响应”。

PBX 连接到我公司的 LAN。需要在我的 LAN 上进行任何配置吗?

我尝试使用相同的代码为 IP:127.0.0.1 发送一个字符串到客户端应用程序并且它工作。但是当我尝试从 PBX 中提取数据时,它不起作用。

我的 PBX 的 LAN 线连接到交换机。

请让我知道我在做什么错误。还指出我使用 C# 从 PBX 捕获数据的良好示例。

        private void btnstartserver_Click(object sender, EventArgs e)
{

int portno = Convert.ToInt32(txtportnum.Text);
byte[] receivedBytes = new byte[1024];
IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, portno);//2112
txtboxstatus.Text = "Creating socket object...";

Socket listener = new Socket(AddressFamily.InterNetworkV6,
SocketType.Stream,
ProtocolType.Tcp);

listener.Bind(ipEndPoint);
listener.Listen(10);
txtboxstatus.AppendText("Listening on " + ipHost.AddressList[0].ToString() + ":" + portno.ToString() + "\r\n");


Socket socket = listener.Accept();

txtboxstatus.AppendText ( "\n Connected with ..." + ipEndPoint.Port);

string receivedvalue = string.Empty;


receivedvalue = ReadMessage(socket);
txtboxstatus.AppendText("\n Message read.....trying to write to the file...");
//writing the received value from client into a file.
try
{
FileStream fs = new FileStream("E:/Demo/IpData/Call.txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write(receivedvalue);
sw.Dispose();
fs.Dispose();
}
catch (Exception ex)
{
txtclient.AppendText(ex.Message);
}
}

更新到这个问题。
我已经编写了一个新代码来连接到 PBX。使用新代码我能够连接到 PBX。请在下面找到。
private void btnTx_Click(object sender, EventArgs e)
{
byte[] receivedBytes = new byte[1024];

int portno = Convert.ToInt32(txtportnum.Text);
IPHostEntry ipHost = Dns.GetHostByName("192.168.x.yyy");
IPAddress ipAddress = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, portno);
txtstatus.Text = "Creating socket object...";

Socket send_soc = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);

send_soc.Connect(ipEndPoint);
txtstatus.AppendText("\nSuccessfully connected to:" + "\t" + send_soc.RemoteEndPoint);
txtstatus.AppendText("\nConnecting via :" + "\t" + send_soc.LocalEndPoint);

string sendingMessage = "abcde";





SendMessage(send_soc, sendingMessage);

int totalBytesReceived = send_soc.Receive(receivedBytes);

string dff = "";
string s = System.Text.ASCIIEncoding.ASCII.GetString(receivedBytes, 0, totalBytesReceived);

txtRx.AppendText(s);
send_soc.Shutdown(SocketShutdown.Both);
send_soc.Close();
try
{
FileStream dr = new FileStream("E:/Demo/IpData/Call.txt", FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);
StreamReader fg = new StreamReader(dr);
string df = fg.ReadToEnd();
dff = df;
fg.Dispose();
dr.Dispose();
}
catch (Exception dfjdfs)
{
throw dfjdfs;
}
try
{
File.Delete("E:/Demo/IpData/Call.txt");
}
catch (Exception jhu)
{
throw jhu;
}
try
{
FileStream cd = new FileStream("E:/Demo/IpData/Call.txt", FileMode.Create);
StreamWriter cdf = new StreamWriter(cd);
cdf.Write(dff);
cdf.Write(s);
cdf.Dispose();
cd.Dispose();
}
catch (Exception hgy)
{
throw hgy;
}

}

static void SendMessage(Socket socket, string msg)
{
byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(msg);

socket.Send(data);
}

但我无法从 PBX 接收任何数据,除了“-”加上我在“sendingMessage”变量中发送的任何数据。例如,如果 sendMessage="abcde",我将收到 -abcde

此外,文档还描述了如何配置 PBX 盒子。同样,为了让 PBX 返回数据,我们需要发送有效的凭据。如何发送此有效凭据?

最佳答案

您应该输入“SMDR”并在“-”后输入进入 smdr 模式,然后输入“PCCSMDR”作为密码并输入松下公共(public)型号。

关于c# - 使用 c# 从 Panasonic PBX 捕获数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20065586/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com