// // Constructor // public CommandServer(ICommandServerListener listener, CommmandServerMode mode, string ipAddress = "") { if (listener == null) { throw new Exception("The listener can't be null!"); } m_listener = listener; m_mode = mode; // This the setup on a new task new Task(async() => { try { if (mode == CommmandServerMode.Server) { // Bind the socket m_socketListener = new StreamSocketListener(); m_socketListener.ConnectionReceived += SocketAccpet; await m_socketListener.BindServiceNameAsync("" + GLOW_SERVER_PORT); } else { if (ipAddress == null) { throw new Exception("The Ip address can't be empty!"); } // Open the socket m_socket = new StreamSocket(); await m_socket.ConnectAsync(new Windows.Networking.HostName(ipAddress), GLOW_SERVER_PORT + ""); // Start the listener ServiceSocket(m_socket); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Socket Create Failed: " + e.Message); m_listener.OnFatalError(); } }).Start(); }
// // Constructor // public CommandServer(ICommandServerListener listener, CommmandServerMode mode, string ipAddress = "") { if (listener == null) { throw new Exception("The listener can't be null!"); } m_listener = listener; m_mode = mode; // This the setup on a new task new Task(async () => { try { if (mode == CommmandServerMode.Server) { // Bind the socket m_socketListener = new StreamSocketListener(); m_socketListener.ConnectionReceived += SocketAccpet; await m_socketListener.BindServiceNameAsync("" + GLOW_SERVER_PORT); } else { if(ipAddress == null) { throw new Exception("The Ip address can't be empty!"); } // Open the socket m_socket = new StreamSocket(); await m_socket.ConnectAsync(new Windows.Networking.HostName(ipAddress), GLOW_SERVER_PORT + ""); // Start the listener ServiceSocket(m_socket); } } catch(Exception e) { System.Diagnostics.Debug.WriteLine("Socket Create Failed: " + e.Message); m_listener.OnFatalError(); } }).Start(); }