Пример #1
0
        /// <summary>
        /// Parse client request
        /// </summary>
        /// <param name="state"></param>
        /// <param name="handlerSocket"></param>
        private void ParseRequest(ChatHelper.StateObject state, StreamSocket handlerSocket)
        {
            var data = new Data(state.Buffer);
            if (data.Command == Command.Disconnect)
            {
                DisconnectClient(handlerSocket);
                return;
            }

            var clientStr = clients.FirstOrDefault(cl => cl.UserName == data.To);
            if (clientStr == null) 
                return;

            var writer = new DataWriter(clientStr.Connection.OutputStream);
            writer.WriteBytes(data.ToByte());

        }
Пример #2
0
 /// <summary>
 /// Parse client request
 /// </summary>
 /// <param name="state"></param>
 /// <param name="handlerSocket"></param>
 private void ParseRequest(ChatHelper.StateObject state, Socket handlerSocket)
 {
     var data = new Data(state.Buffer);
     if (data.Command == Command.Disconnect)
     {
         DisconnectClient(state.InputStream);
         return;
     }
     var clientStr = clients.FirstOrDefault(cl => cl.UserName == data.To);
     if (clientStr == null) 
         return;
     clientStr.Connection.Send(data.ToByte());
     handlerSocket.BeginReceive(state.Buffer, 0, ChatHelper.StateObject.BUFFER_SIZE, 0,
       OnReceive, state);
 }