/// <summary> /// Start and Connect a new <see cref="IClient{T}" /> /// </summary> /// <typeparam name="T">The Type of object to send over the network</typeparam> /// <param name="address">The <see cref="IServer{T}" />'s <see cref="IPAddress" /></param> /// <param name="port">The <see cref="IServer{T}" />'s Port</param> /// <param name="newThread"> /// Whether to use a seperate /// <see cref="System.Threading.Thread" /> for all data transfers /// </param> /// <returns>A connected <see cref="IClient{T}" /> instance</returns> public static async Task <IClient <T> > StartNewClient <T>(string address, int port, bool newThread) { var client = new ProtoClient <T>(IPAddress.Parse(address), port); await client.Connect(newThread); return(client); }
private static void StartClient() { _client = new ProtoClient <string>(ServerIp, 1024); _client.AutoReconnect = true; _client.Connect().GetAwaiter().GetResult(); _client.ReceivedMessage += ClientMessageReceived; _client.ConnectionLost += Client_ConnectionLost; _client.Send("Hello Server!").GetAwaiter().GetResult(); }
public void StartClient() { Console.WriteLine("Connecting"); try { _client.Connect().GetAwaiter().GetResult(); } catch { MessageBox.Show("Server disconnected"); Environment.Exit(0); // Force close to prevent close confirmation } }