Legacy product's VB6 WinSock Tcp clients simply "miss" half of the message sent to them.
I'm going to be working on a server project where an old legacy application written in VB6 will be required to connect to the C# TCP server.
TCP client/server programming has always been easy when both endpoints are .NET thanks to System.Net.TcpClient. However it looks like the VB6 group will be stuck with VB6 WinSock control (is this as bad as I heard it is?).
Are there any caveats or tips leading into this so that any avoidable landmines or obstacles can be taken care of?
A current implementation has a server (c#.net) that sends messages in the following way:
private bool SendToStream(NetworkStream clientStream, string message)
{
try
{
message = Crypto.Encrypt(message);
message = message + "\r\n";
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(message.ToCharArray());
if (clientStream != null)
{
StreamWriter blah = new StreamWriter("lastsent_a.txt");
blah.WriteLine("[some clientStream]" + Environment.NewLine + Environment.NewLine + message + Environment.NewLine + Environment.NewLine + Crypto.Decrypt(message));
blah.Close();
clientStream.Write(buffer, 0, buffer.Length);
clientStream.Flush();
return true;
}
return false;
}
catch (Exception e)
{
ProcessDebugLog("ERROR - SendToStream: " + e.Message.ToString());
return false;
}
}
Where clientStream is the NetworkStream associated with the TcpClient that was built from a TcpListener.
The client receives messages in the following way (VB6 WinSock style):
Private Sub wskConnect_DataArrival(ByVal bytesTotal As Long)
Dim sBuff As String
wskConnect.GetData sBuff, vbString '-- Retrieve sent value
ProcessMessage sBuff '-- Process the value
End Sub
EDIT: When I want to debug Tcp clients in C# I use a TcpListener's NetworkStream and do .Receive synchronously. Clearly this hogs the processor, but it let's me get every single byte coming down the line, instead of having to just trust that an async socket event will fire. Would switching the VB6 code to do this synchronously and remove that blind trust in an event firing be a good place to start?