JavaScript等价于C#TCPclient发送
我正在尝试将数据从C#应用程序发送到TCP服务器并从中获得响应,只是想知道是否有JavaScript命令或框架相当于TCP客户端到服务器的通信?下面是我正在使用的C#代码,这段代码运行良好,但我计划创建一个web应用程序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;
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示例:这是否回答了您的问题?