I made this code here following some tutorials on the internet.
buttonAbrirConexão.Enabled = false;
TcpListener servidor = new TcpListener(6554);
servidor.Start();
while(true)
{
Thread.Sleep(2500);
if(servidor.Pending())
{
MessageBox.Show("Cliente conectado");
Socket conexão = servidor.AcceptSocket();
socketStream = new NetworkStream(conexão);
escrever = new BinaryWriter(socketStream);
ler = new BinaryReader(socketStream);
escrever.Write("Alguma coisa");
break;
}
}
Before using ler.Read(),
how will I know if the customer sent me something before? How do you know what he told you to do? String
? int
?
Is there a way to fire an asynchronous event every time a client tries to connect?