我编写了以下代码来从 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”变量中发送的任何内容。例如,如果正在发送消息 =“abcde”,我将收到-abcde
此外,文档还描述了如何配置 PBX 盒子。同样,为了让 PBX 返回数据,我们需要发送有效的凭据。如何发送此有效凭据?