S
sebastian.harko
Hello,
I have a question on socket programming in C#.
I have this code and it doesn't work correctly.
It sends the message correctly but it does not get the message that
the server sends back ( the program bellow gets blocked ). I know for
sure
that the server sends back a message ( I'm using a traffic sniffer and
I can
see what's being sent and received ) .'
....
So what's wrong here ?
best regards
TcpClient client = new TcpClient(hostName, pacsPort);
try
{
NetworkStream s = client.GetStream();
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
sw.AutoFlush = true;
sw.Write(message);
string response = sr.ReadLine(); // program blocks
here
Console.Write(response);
sw.Close();
sr.Close();
s.Close();
client.Close();
}
catch (Exception e)
{
Console.WriteLine("Error.");
}
I have a question on socket programming in C#.
I have this code and it doesn't work correctly.
It sends the message correctly but it does not get the message that
the server sends back ( the program bellow gets blocked ). I know for
sure
that the server sends back a message ( I'm using a traffic sniffer and
I can
see what's being sent and received ) .'
....
So what's wrong here ?
best regards
TcpClient client = new TcpClient(hostName, pacsPort);
try
{
NetworkStream s = client.GetStream();
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
sw.AutoFlush = true;
sw.Write(message);
string response = sr.ReadLine(); // program blocks
here
Console.Write(response);
sw.Close();
sr.Close();
s.Close();
client.Close();
}
catch (Exception e)
{
Console.WriteLine("Error.");
}