public static IPEndPoint GetEndPoint() { IPAddress ipAddr = ServerIPAddress.GetServerIPAddress(); IPEndPoint endPoint = new IPEndPoint(ipAddr, 11111); return(endPoint); }
public static Socket GetSocket() { // Creation of TCP/IP Socket using Socket Class Costructor IPAddress ipAddr = ServerIPAddress.GetServerIPAddress(); socket = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp); return(socket); }
// ExecuteClient() Method static void ExecuteClient() { try { //Get Server's IP Address IPAddress ipAddr = ServerIPAddress.GetServerIPAddress(); //Get Network Address IPEndPoint endPoint = NetworkAddress.GetEndPoint(); try { Console.WriteLine("Client Started!"); //Establish connection to Server ConnectionHandler.EstablishConnection(); //Send yourAliasToServer UserAlias.SendYourAliasToServer(); //Perfrom Chat Messenger.PerformChat(UserAlias.GetYourAlias(), FriendsAlias.GetFriendsAlias()); //Close Connection ConnectionHandler.GetSocket().Shutdown(SocketShutdown.Both); ConnectionHandler.GetSocket().Close(); } // Manage of Socket's Exceptions catch (ArgumentNullException ane) { Console.WriteLine("ArgumentNullException : {0}", ane.ToString()); } catch (SocketException se) { Console.WriteLine("SocketException : {0}", se.ToString()); } catch (Exception e) { Console.WriteLine("Unexpected exception : {0}", e.ToString()); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }