Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript等价于C#TCPclient发送_Javascript_C# - Fatal编程技术网

JavaScript等价于C#TCPclient发送

JavaScript等价于C#TCPclient发送,javascript,c#,Javascript,C#,我正在尝试将数据从C#应用程序发送到TCP服务器并从中获得响应,只是想知道是否有JavaScript命令或框架相当于TCP客户端到服务器的通信?下面是我正在使用的C#代码,这段代码运行良好,但我计划创建一个web应用程序 private void sendDataToTCPServer() { string message = "Hello Server!"; string IP = ip_text.Text;

我正在尝试将数据从C#应用程序发送到TCP服务器并从中获得响应,只是想知道是否有JavaScript命令或框架相当于TCP客户端到服务器的通信?下面是我正在使用的C#代码,这段代码运行良好,但我计划创建一个web应用程序

private void sendDataToTCPServer()
        {

            string message =  "Hello Server!";

            string IP = ip_text.Text;
            int port =  server_port.Text); 
            try
            {

                TcpClient client = new TcpClient(IP, port); 


                Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);


                NetworkStream stream = client.GetStream();


                stream.Write(data, 0, data.Length);



                data = new Byte[256];


                String responseData = String.Empty;


                Int32 bytes = stream.Read(data, 0, data.Length);

                responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);

                Message.Show(resposeData);
                stream.Close();
                client.Close();
            }
            catch (ArgumentNullException an)
            {


                MessageBox.Show(String.Format("ArgumentNullException: {0}", an.Message), "PLC Error Information", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            catch (SocketException se)
            {


                MessageBox.Show(String.Format("SocketException: {0}", se.Message), "PLC Error Information", MessageBoxButtons.OK, MessageBoxIcon.Error);


            }
        } 

您可以使用现有的托管asp.net web应用程序


下面是一个js示例:

这是否回答了您的问题?