title: How I can get the AspNetWebSocketContext from the current context?
body: <p>I am implementing ASP.net websocket server using Microsoft webscoket. I have a function which sends data to the client. Below is the class.</p>
  
  <pre><code>public class MyWebSocketHandler : IHttpHandler
      {
  
          public void ProcessRequest(HttpContext context)
          {
              if (context.IsWebSocketRequest)
              {
                  context.AcceptWebSocketRequest(DoTalking);
  
              }
          }
  
          public bool IsReusable
          {
              get
              {
                  return false;
              }
          }
  
          public async Task DoTalking(AspNetWebSocketContext context)
          {
              WebSocket socket = context.WebSocket;
              while (true)
              {
                  ArraySegment&lt;byte&gt; buffer = new ArraySegment&lt;byte&gt;(new byte[1024]);
                  WebSocketReceiveResult result = await socket.ReceiveAsync(buffer, CancellationToken.None);
                  if (socket.State == WebSocketState.Open)
                  {
                      string userMessage = Encoding.UTF8.GetString(buffer.Array, 0, result.Count);
                      userMessage = "Message from client : " + userMessage;
  
                  }
                  else
                  {
                      break;
                  }
              }
          }
  
          public async Task SendToClient(AspNetWebSocketContext context)
          {
              WebSocket socket = context.WebSocket;
              //WebSocket socket = context.WebSocket;
              ArraySegment&lt;byte&gt; buffer = new ArraySegment&lt;byte&gt;(new byte[1024]);
              buffer = new ArraySegment&lt;byte&gt;(Encoding.UTF8.GetBytes(message));
              await socket.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None);
          }
  
          public void callSendToClient()
          {
                  var task = SendToClient(Problem is here!);
                  task.Wait();  
          }
  
          private string message { get; set; }
      }
  }
  </code></pre>
  
  <p>My problem is how to get the AspNetWebSocketContext when I call the SendToClient method ? I am stuck at this point. Actually I want to call SendToClient() method from another .aspx page. Need some help.</p>