Esempio n. 1
0
        private async Task <string> ReceiveFromSocket(ClientWebSocket theSocket)
        {
            // receive

            var arraySegment = new ArraySegment <byte>(new Byte[1024 * 256]);
            var res          = await theSocket.ReceiveAsync(arraySegment, CancellationToken.None);

            return(Encoding.UTF8.GetString(arraySegment.Actualize(res.Count))); // helper in WebSocketServer.dll
        }
Esempio n. 2
0
 protected Task <string> GetFromBufferAsString(ArraySegment <byte> buffer, Tuple <int, bool, int> received)
 {
     return(Task.Factory.StartNew(function: () =>
     {
         var bytes = buffer.Actualize(received.Item3);
         var message = Encoding.UTF8.GetString(bytes);
         return message;
     }
                                  ));
 }
Esempio n. 3
0
 protected Task <O> GetFromBufferAsJson <O>(ArraySegment <byte> buffer, Tuple <int, bool, int> received) where O : new()
 {
     return(Task.Factory.StartNew <O>(function: () =>
     {
         var messageLength = received.Item3;
         var actual = buffer.Actualize(messageLength);
         return JsonConvert.DeserializeObject <O>(Encoding.UTF8.GetString(actual));
     }
                                      ));
 }
        private async Task<string> ReceiveFromSocket(ClientWebSocket theSocket)
        {

            // receive 
            
            var arraySegment = new ArraySegment<byte>(new Byte[1024 * 256]);
            var res = await theSocket.ReceiveAsync(arraySegment, CancellationToken.None);

            return Encoding.UTF8.GetString(arraySegment.Actualize(res.Count));
        }