1

I have written the below code to capture data from Panasonic PBX(KX-TDE 100/200) and write it to a file. When I try to run the below code, it shows "not responding" in the Task Manager.
Also I tried to debug where might be the problem.The line

Socket socket = listener.Accept(); will be hit while debugging and after that it shows "Not Responding".

The PBX is connected to LAN in my company.Any configurations need to be done on my LAN?

I tried the same code for IP:127.0.0.1 to send a string to client app and it worked.But when I tried to pull data from PBX, its not working.

The LAN wire from my PBX is connected to the switch.

Please let me know what mistake I am doing. Also point me to good samples on capturing data from PBX using C#.

        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); 
        }  
     }

Update to this question.
I have written a new code to connect to PBX.With the new code I was able to connect to the PBX.Please find below.

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);
    }

But I am not able to receive any data from PBX except "-" plus whatever I send in "sendingMessage" variable.For example if sendingMessage="abcde",I will receive -abcde

Also the documentation is describing how to configure PBX box.Also for the PBX to return the data, we need to send valid credentials. How to send this valid credentials?

DotNetTide
  • 9
  • 1
  • 4
  • Are you,sure that you don't need a valid credentials to connect whit the PBX, many of those machines require credentials to interact whit it. – Juan Pablo Gomez Nov 20 '13 at 12:12
  • @JuanPabloGomez:- yes it is required,I just came to know about it. So how should I supply valid credentials to connect with the PBX. Any sample or link???? – DotNetTide Nov 21 '13 at 12:30
  • sorry for the delay, it depends on each model, you must read the PBX manual. maybe in the command line section. Maybe this link could help you http://www.voicesonic.com/panasonic/manuals/KX-TDE_100_200_600/KXTDE_Programming_Manual-100-200-600.pdf – Juan Pablo Gomez Nov 21 '13 at 20:11
  • @JuanPabloGomez :-I was able to make a connection to the PBX without supplying any credentials, but I am not receiving any data. I only get "\r-" as 13 45 respectively present in byte array. Also the manual is not mentioning anything about passing credentials.It is just saying about PBX management Console. So would you give me an example of supplying credentials for the PBX model which you are aware of? If I supply credentials I may get data. – DotNetTide Nov 22 '13 at 08:43

2 Answers2

1

You should type "SMDR" and enter after "-" for going to smdr mode, then type "PCCSMDR" as password and enter for public Panasonic models.

SINA
  • 11
  • 3
0

Don't make blocking calls, (like accept), in a GUI event-handler.

Thread off the server or use asynch.

Martin James
  • 24,453
  • 3
  • 36
  • 60