public void Listen(int port) { var server = new TcpServerSocket(); server.OnClientConnect += onConnected; server.Listen(port); socket = server; }
public void Connect(IPAddress ip, int port) { var client = new TcpClientSocket(); client.OnConnect += onConnected; client.Connect(ip, port); socket = client; }
static void initServer(string[] args) { int port = 0; try { port = int.Parse(args[1]); var server = new TcpServerSocket(); server.OnDisconnect += onDisconnect; server.Listen(port); _socket = server; start(); } catch (Exception) { Console.WriteLine("Invalid port"); } }
static void initClient(string[] args) { IPAddress ip = null; int port = 0; try { ip = IPAddress.Parse(args[1]); port = int.Parse(args[2]); var client = new TcpClientSocket(); client.OnDisconnect += onDisconnect; client.Connect(ip, port); _socket = client; start(); } catch (Exception) { Console.WriteLine("Please specify a valid ip and port"); } }