// Initialize the connection with the server public void Connect(IPAddress ip, int port) { IpAddress = ip; Port = port; Client = new TcpClient(); // initialize a TCP connection with the server try { Client.Connect(IpAddress, port); // connecting using the ip and port number provided } catch (SocketException e) { Console.WriteLine(e); return; } // updating our variables Connected = true; Controller.RaiseStateChangeEvent(new ClientStateChangedEvent(Connected)); Stream = Client.GetStream(); // start the thread to receive messages ThrReceive = new Thread(new ThreadStart(Receive)); ThrReceive.Start(); }