private static void OnReceive() { byte[] _sizeinfo = new byte[4]; byte[] _recivedbuffer = new byte[1024]; int totalLeido = 0, actualLeido = 0; try { actualLeido = totalLeido = _clientSocket.Receive(_sizeinfo); if (totalLeido <= 0) { Console.WriteLine("No esta conectado al servidor"); } else { while (totalLeido < _sizeinfo.Length && actualLeido > 0) { actualLeido = _clientSocket.Receive(_sizeinfo, totalLeido, _sizeinfo.Length - totalLeido, SocketFlags.None); totalLeido += actualLeido; } int messagesize = 0; messagesize = _sizeinfo[0]; messagesize = (_sizeinfo[1] << 8); messagesize = (_sizeinfo[2] << 16); messagesize = (_sizeinfo[3] << 24); byte[] data = new byte[messagesize]; totalLeido = 0; actualLeido = totalLeido = _clientSocket.Receive(data, totalLeido, data.Length - totalLeido, SocketFlags.None); while (totalLeido < messagesize && actualLeido > 0) { actualLeido = _clientSocket.Receive(data, totalLeido, data.Length - totalLeido, SocketFlags.None); totalLeido += actualLeido; } //manejar la informacion de la red ClientManejadorDeDatosRed.manejadorInfoDeRed(data); } } catch (Exception e) { Console.WriteLine("No esta conectado al servidor..."); Console.WriteLine(e); } }
static void Main(string[] args) { ClientManejadorDeDatosRed.IniciadorPaquetesRed(); ClientTCP.ConnectToServer(); Console.ReadLine(); }