public void Connect(IAsyncResult ar) { try { this.Client.EndConnect(ar); this.Stream = this.Client.GetStream(); SendData(this.Name); this.Stream.BeginRead(this.Buffer, 0, this.Buffer.Length, new AsyncCallback(OnIntRead), null); } catch (Exception) { OnMessageBoxShow?.Invoke("The server is not online, press \"OK\" to close the window.", MessageBoxButtons.OK); } }
private void handleData(Sentence data) { try { switch (data.getMessageType()) { case Sentence.Type.SERVER_MESSAGE: { OnChatReceived?.Invoke($"{data.getSender()}: {data.getData()}\r\n"); break; } case Sentence.Type.USERSMESSAGE: { OnClientListReceived?.Invoke(data.Data); Console.WriteLine("All clients: "); Console.WriteLine(data.Data); break; } case Sentence.Type.DISCONNECT_REQUEST: { SendData("$DISCONNECT"); OnMessageBoxShow?.Invoke($"You got kicked!\nReason: {data.getData()}", MessageBoxButtons.OK); break; } default: break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } }