Exemple #1
0
 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);
 }
Exemple #2
0
        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
            }
        }
Exemple #3
0
        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);
                }
            }
        }
Exemple #4
0
        public void on(string route, Action <UTodoJsonObject> callback)
        {
            var data = UTodoMessage.PackMessage("on." + route);

            clientSocket.BeginSend(data, 0, data.Length, SocketFlags.None, SendCallback, callback);
        }
Exemple #5
0
        public void notify(string route, UTodoJsonObject jsonObject)
        {
            var data = UTodoMessage.PackMessage("notify." + route, jsonObject);

            clientSocket.BeginSend(data, 0, data.Length, SocketFlags.None, SendCallback, null);
        }
Exemple #6
0
 public UTodoClient()
 {
     message      = new UTodoMessage();
     clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 }