It looks like you're trying to multiplex multiple data streams on one socket. So you may be running into a thread switching problem while waiting for the server, but if that's the case you're probably doing something like this, which is an inappropriate way to multithread.
void Task(int type)
{
// Authenticate
// Send Data
// Disconnect
}
// Connect
Thread.Start(Task(1));
Thread.Start(Task(2));
Thread.Start(Task(3));
If you've got threads 1, 2, and 3 doing work on the server in tandem you've got a few ways to do it:
1.) Do your work threaded with different connections
void Task(int type)
{
// Connect
// Authenticate
// Send Data
// Disconnect
}
Thread.Start(Task(1));
Thread.Start(Task(2));
Thread.Start(Task(3));
2.) Do your work singlethreaded with one connection
void Task(int type)
{
// Send Data
}
// Connect
// Authenticate
Task(1);
Task(2);
Task(3);
// Disconnect
3.) Use multiple connections