public UTodoServerClient(Socket client, UTodoServer server) { this.client = client; this.server = server; message = new UTodoMessage(); message.clientSocket = client; client.BeginReceive(message.buffer, 0, UTodoMessage.bufferSize, SocketFlags.None, RecieveCallback, null); }
public static void handleObserver(string router, UTodoJsonObject jsonObject) { var clients = observers[router]; foreach (var client in clients) { client.ClientSocket.Send(UTodoMessage.PackMessage(jsonObject)); //todo error } }
private void RecieveCallback(IAsyncResult result) { int byteCount = clientSocket.EndReceive(result); if (byteCount > 0) { message.stringBuilder.Append(Encoding.ASCII.GetString(message.buffer, 0, byteCount)); string content = message.stringBuilder.ToString(); if (content.IndexOf("<EOF>") > -1) { UTodoMessage.ReadMessage(content, Debug.Log); } else { clientSocket.BeginReceive(message.buffer, 0, UTodoMessage.bufferSize, SocketFlags.None, RecieveCallback, message); } } }
public void on(string route, Action <UTodoJsonObject> callback) { var data = UTodoMessage.PackMessage("on." + route); clientSocket.BeginSend(data, 0, data.Length, SocketFlags.None, SendCallback, callback); }
public void notify(string route, UTodoJsonObject jsonObject) { var data = UTodoMessage.PackMessage("notify." + route, jsonObject); clientSocket.BeginSend(data, 0, data.Length, SocketFlags.None, SendCallback, null); }
public UTodoClient() { message = new UTodoMessage(); clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); }