R
Ryan
Hi All.
I am using .NET 2.0 on Windows XP SP3.
Trying to send a message to network device (<ESC>B<ENQ>) that will
then send a response back.
I using Hyperterminal and the Send text file function a can send the
message to the device and get the response back that I expect.
However, using the C# below it simply gets stuck on the stream.Read
method call.
Any ideas or help will be appreciated.
TIA.
R
String cmd = Char.ConvertFromUtf32(5);
cmd += Char.ConvertFromUtf32(66);
cmd += Char.ConvertFromUtf32(27);
TcpClient client = new TcpClient("192.168.0.80", 6001);
client.NoDelay = true;
Byte[] data = System.Text.Encoding.ASCII.GetBytes(cmd);
NetworkStream stream = client.GetStream();
// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);
Console.WriteLine("Sent: {0}",
cmd);
// Buffer to store the response bytes.
Byte[] respdata = new Byte[256];
// String to store the response ASCII representation.
String responseData = String.Empty;
// Read the first batch of the TcpServer response bytes.
Int32 bytes = stream.Read(respdata, 0, respdata.Length);
responseData = System.Text.Encoding.ASCII.GetString
(respdata, 0, bytes);
Console.WriteLine("Received: {0}", responseData);
// Close everything.
stream.Close();
client.Close();
I am using .NET 2.0 on Windows XP SP3.
Trying to send a message to network device (<ESC>B<ENQ>) that will
then send a response back.
I using Hyperterminal and the Send text file function a can send the
message to the device and get the response back that I expect.
However, using the C# below it simply gets stuck on the stream.Read
method call.
Any ideas or help will be appreciated.
TIA.
R
String cmd = Char.ConvertFromUtf32(5);
cmd += Char.ConvertFromUtf32(66);
cmd += Char.ConvertFromUtf32(27);
TcpClient client = new TcpClient("192.168.0.80", 6001);
client.NoDelay = true;
Byte[] data = System.Text.Encoding.ASCII.GetBytes(cmd);
NetworkStream stream = client.GetStream();
// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);
Console.WriteLine("Sent: {0}",
cmd);
// Buffer to store the response bytes.
Byte[] respdata = new Byte[256];
// String to store the response ASCII representation.
String responseData = String.Empty;
// Read the first batch of the TcpServer response bytes.
Int32 bytes = stream.Read(respdata, 0, respdata.Length);
responseData = System.Text.Encoding.ASCII.GetString
(respdata, 0, bytes);
Console.WriteLine("Received: {0}", responseData);
// Close everything.
stream.Close();
client.Close();