/// <summary> /// The function starts the the communication /// between the GUI and the server /// </summary> private void Start() { if (!Connected) { return; } Task task = new Task(() => { while (true) { try { string strMessage = m_client.Read(); MessageArrived?.Invoke(this, new CommandMessageEventArgs { Message = CommandMessage.FromJSONString(strMessage) }); } catch (IOException ex) { break; } } }); task.Start(); }
public void HandleClient(IClientWrapper client) { Task task = new Task(() => { try { while (true) { string message = client.Read(); if (message == null) { client.Close(); break; } long length = message.Length; CommandMessage cmd = CommandMessage.FromJSONString(message); bool result; string newMessage = m_controller.ExecuteCommand((int)cmd.Type, cmd.Args, out result); if (result) { client.Write(newMessage); } } } catch (IOException ex) { client.Close(); } }); task.Start(); }