I
Isi Robayna
Hello,
I am trying to communicate with a legacy socket server. The first thing this
legacy server does upon getting a client connection is to send an ID back to
the client... I am trying to read that ID Value. By the way, that ID is an
uint (32 bit unsigned integer)
I have tried a number of different things to translate the buffer coming in
to the a number, and I cannot translate the number(ID) in the buffer to a
uint .....
Any help welcome.
Thanks,
Isi r.
Here is the code:
TcpClient myClientSocket;
try
{
myClientSocket = new TcpClient("127.0.0.1",9099);
}
catch (Exception ex)
{
Console.WriteLine("Error connecting socket:" + ex.ToString());
return;
}
NetworkStream networkStream = myClientSocket.GetStream();
try
{
byte[] myDataBuffer = new byte[4];
String responseData = String.Empty;
int bytes = networkStream.Read(myDataBuffer,0, myDataBuffer.Length);
uint myThreadID;
Array.Reverse(myDataBuffer); // reverse (little/big endian
issues) --not sure if I need this
responseData = System.Text.Encoding.ASCII.GetString(myDataBuffer,0,4);
myThreadID = Convert.ToUInt32 ( responseData ); // <=== always get
zero...
Console.WriteLine("Received: {0} {1}", responseData, myThreadID);
}
catch
{
}
myClientSocket.Close();
myClientSocket = null;
}
I am trying to communicate with a legacy socket server. The first thing this
legacy server does upon getting a client connection is to send an ID back to
the client... I am trying to read that ID Value. By the way, that ID is an
uint (32 bit unsigned integer)
I have tried a number of different things to translate the buffer coming in
to the a number, and I cannot translate the number(ID) in the buffer to a
uint .....
Any help welcome.
Thanks,
Isi r.
Here is the code:
TcpClient myClientSocket;
try
{
myClientSocket = new TcpClient("127.0.0.1",9099);
}
catch (Exception ex)
{
Console.WriteLine("Error connecting socket:" + ex.ToString());
return;
}
NetworkStream networkStream = myClientSocket.GetStream();
try
{
byte[] myDataBuffer = new byte[4];
String responseData = String.Empty;
int bytes = networkStream.Read(myDataBuffer,0, myDataBuffer.Length);
uint myThreadID;
Array.Reverse(myDataBuffer); // reverse (little/big endian
issues) --not sure if I need this
responseData = System.Text.Encoding.ASCII.GetString(myDataBuffer,0,4);
myThreadID = Convert.ToUInt32 ( responseData ); // <=== always get
zero...
Console.WriteLine("Received: {0} {1}", responseData, myThreadID);
}
catch
{
}
myClientSocket.Close();
myClientSocket = null;
}