Socket does not get a response

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();
 
P

Peter Duniho

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.

Impossible to know for sure without a concise-but-complete code example.
However, even assuming the character conversion keeps your input intact as
their original values, the characters you are sending are in the reverse
order from what you say you want to send.

You also should not be using the NoDelay property, but that wouldn't cause
a basic transmission problem.

There are any number of things that could be causing your problem, most of
which have nothing to do with your C# code. Other than the reversed
character issue, there's nothing that stands out as blatantly wrong that
might prevent you from receiving a response, so without a
concise-but-complete code example, it's not really possible to say what
might be wrong.

Pete
 
R

Ryan

Impossible to know for sure without a concise-but-complete code example.  
However, even assuming the character conversion keeps your input intact as  
their original values, the characters you are sending are in the reverse  
order from what you say you want to send.

You also should not be using the NoDelay property, but that wouldn't cause  
a basic transmission problem.

There are any number of things that could be causing your problem, most of  
which have nothing to do with your C# code.  Other than the reversed  
character issue, there's nothing that stands out as blatantly wrong that  
might prevent you from receiving a response, so without a  
concise-but-complete code example, it's not really possible to say what  
might be wrong.

Pete

Thanks Pete,

Turns out you spotted the problem. I had the command string reversed.

Simply could not see the wood for the trees...

Cheers,
R
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top