Click here to Skip to main content
15,882,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two system that I need to get talking together over sockets (preferably TCP).
I tried a Perl client to a C# socket server but the Perl client stopped after sending the message, I think there was an acknowledgement problem.
Does anyone have experience of this?
I have Perl-Perl and C#-C# working fine.
Thanks.
Posted

Hard to say without seeing the implementations, but sockets are supposed to be language agnostic, so one of your implementations has a bug (or perhaps both).
 
Share this answer
 
Got it working, test sample below (runs in a separate thread):
        public void Listen()
        {
            int ByteRead;
            IPAddress ipAddress = Dns.GetHostAddresses("localhost")[0];
            TcpListener tcpListener = new TcpListener(IPAddress.Any, 399);
            TcpClient tcpClient;
#if CONSOLE_DEBUG
            Console.WriteLine("Socket created.");
#endif
            while (true)
            {
#if CONSOLE_DEBUG
                Console.WriteLine("Listener created.");
#endif
                while (true)
                {
                    try 
                    {
                        tcpListener.Start();
                    }
                    catch ( SocketException se)
                        {
                            Console.WriteLine(se.Message);
                        }
                    tcpClient = tcpListener.AcceptTcpClient();
                    NetworkStream ns = tcpClient.GetStream();
                    while ((ByteRead = ns.ReadByte()) <= 0) { };    // Wait until a non zero byte is received
                    Console.WriteLine("Length = {0}", ByteRead);
                    string TempStr = new string(' ', 0);
                    for (int loop = 0; loop < ByteRead; loop++)
                    {
                        TempStr += (char)ns.ReadByte();
                    }
                    Console.WriteLine("\"{0}\" received", TempStr);
                    lock (TextBox1)
                    {
                        //TextBox1.AppendText(string.Format("{0}\r\n", TempStr));
                    }
                    ns.Close();
                }
                tcpClient.Close();
                Console.WriteLine("Listen ended.");
            }
        } 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900