public static TAClient createClient(TAServer server, TcpClient clientConnection) { TAClient c = new TAClient(server, clientConnection); WebsocketUtility.websocketHandshake(clientConnection); new Thread(c.clientListenCycle).Start(); return(c); }
private TAClientListener(TAServer server) { this.server = server; TAServerLog.log("Listening for clients...", LogType.SERVER_ACTION); clientListener = new TcpListener(WebsocketUtility.getLocalIP(), TAServer.CLIENT_LISTEN_PORT); clientListener.Start(); listening = true; }
public void receiveMessage(Byte[] data, TAClient sender) { TAServerLog.log("RX msg from client: " + sender.clientName + ", ID: " + sender.clientID + " at " + DateTime.Now, LogType.CLIENT_MESSAGE_RX); Byte[] decodedMsg = WebsocketUtility.decodeWebsocketMessage(data); string messageString = Encoding.UTF8.GetString(decodedMsg); sender.parseMessage(messageString); //do whatever with the message string from here }
private void sendMessage(string msgStr, params TAClient[] targets) { Byte[] data = Encoding.UTF8.GetBytes(msgStr); Byte[] encodedMessage = WebsocketUtility.encodeWebsocketMessage(data); foreach (var c in targets) { try { if (c.clientStream.CanWrite) { c.clientStream.Write(encodedMessage, 0, encodedMessage.Length); } else { Console.WriteLine("could not write to client stream"); } } catch (System.IO.IOException e) { TAServerLog.log("Send message Failed: " + e.Message, LogType.ERROR); } } }