I am experimenting on sending data from a C# application into a TCP server and get the response from it, just wondering if there's a JavaScript command or framework equivalent to TCP client to server communication? Below is the C# code that i am using, this code works fine but i am planning to create a web application.
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);
}
}