S
Swiftusw
I'm writing a connector for a client to replace an old VB6 system. The
connector works, but is several times slower than the older VB6
connector. I have isolated the problem to be in the connection to the
server. All we are doing is sending a input stream to the server and
receiving an output stream in response. The code is below. Can anybody
see why this would run so much slower than VB6 using the Winsock
ActiveX control?
TIA,
Matt
public string SendMessage(string server, int port, string
requestMessage)
{
TcpClient client = new TcpClient();
client.SendBufferSize = 1024;
client.ReceiveBufferSize = 1024;
StringBuilder responseData = new StringBuilder();
byte[] data = Encoding.ASCII.GetBytes(requestMessage);
client.Connect(server, port);
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
data = new byte[client.ReceiveBufferSize];
int bytes = 0;
while(true)
{
bytes = stream.Read(data, 0, data.Length);
if(bytes>0){
responseData.Append(Encoding.ASCII.GetString(data, 0, bytes));
}
else{
break;
}
}
stream.Close();
client.Close();
return responseData.ToString();
}
connector works, but is several times slower than the older VB6
connector. I have isolated the problem to be in the connection to the
server. All we are doing is sending a input stream to the server and
receiving an output stream in response. The code is below. Can anybody
see why this would run so much slower than VB6 using the Winsock
ActiveX control?
TIA,
Matt
public string SendMessage(string server, int port, string
requestMessage)
{
TcpClient client = new TcpClient();
client.SendBufferSize = 1024;
client.ReceiveBufferSize = 1024;
StringBuilder responseData = new StringBuilder();
byte[] data = Encoding.ASCII.GetBytes(requestMessage);
client.Connect(server, port);
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
data = new byte[client.ReceiveBufferSize];
int bytes = 0;
while(true)
{
bytes = stream.Read(data, 0, data.Length);
if(bytes>0){
responseData.Append(Encoding.ASCII.GetString(data, 0, bytes));
}
else{
break;
}
}
stream.Close();
client.Close();
return responseData.ToString();
}