Perl和C#(2.0)之间的套接字 [英] Sockets between Perl and C# (2.0)

查看:126
本文介绍了Perl和C#(2.0)之间的套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个系统需要通过套接字(最好是TCP)一起交谈.
我尝试将Perl客户端连接到C#套接字服务器,但是Perl客户端在发送消息后停止了运行,我认为这是一个确认问题.
有人有经验吗?
我的Perl-Perl和C#-C#工作正常.
谢谢.

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.

推荐答案

很难说,没有看到实现,但是套接字应该与语言无关,因此您的一个实现有一个bug(或可能有一个bug).
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).


使其正常运行,在下面测试示例(在单独的线程中运行):
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.");
            }
        } 


这篇关于Perl和C#(2.0)之间的套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆