Ejemplo n.º 1
0
        private void BeginConnectCallbackMethod(IAsyncResult result)
        {
            // we get the request that has been passed as state
            // and cast it back to its original class
            MyHttpRequest request = (MyHttpRequest)result.AsyncState;

            // we check to see if the received request is correct or not
            if (request == null)
            {
                return;
            }
            // print message to inform user about the status of the
            // operations
            Console.WriteLine("Identificator " + request.identificator +
                              ": Socket Connection for host=" + request.host);

            HttpParser httpParser = new HttpParser();

            byte[] data = Encoding.ASCII
                          .GetBytes(httpParser.CreateGetRequestString(request.host, request.endpoint));

            // we now move to the BeginSent
            request.socket.BeginSend(data,
                                     0,
                                     data.Length,
                                     0,
                                     BeginSendCallbackMethod,
                                     request);
        }
Ejemplo n.º 2
0
        private async Task SocketBeginSend(MyHttpRequest request)
        {
            HttpParser httpParser = new HttpParser();

            byte[] data = Encoding.ASCII.GetBytes(httpParser.CreateGetRequestString(request.host, request.endpoint));
            request.socket.BeginSend(data,
                                     0,
                                     data.Length,
                                     0,
                                     BeginSendCallbackMethod,
                                     request);
            await Task.FromResult <object>(request.isSent.WaitOne());
        }