I using this kind of code to work with some server:
int port = 6789;
string serverAddress = "127.0.0.1";
string playersName = "random";
TcpClient client = null;
StreamWriter writer = null;
StreamReader reader = null;
try
{
client = new TcpClient();
client.Connect(serverAddress, port);
NetworkStream stream = client.GetStream();
writer = new StreamWriter(stream);
writer.Write("100 " + playersName + "\r\n");
writer.Flush();
reader = new StreamReader(stream);
bool isRunning = true;
while (isRunning)
{
string msg = reader.ReadLine(); //stack in this line
string[] parts = msg.Split(' ');
...
}
}
I've no exception, but my application stack in line with string msg = reader.ReadLine();
and doesn't work. Connection to server is good and work, because server write message that my client app was accesing connection.