示例#1
0
        private static byte[] GetNegotiatePayload(string connectionId, HttpContext context, HttpConnectionOptions options)
        {
            NegotiationResponse response = new NegotiationResponse();

            response.ConnectionId        = connectionId;
            response.AvailableTransports = new List <AvailableTransport>();

            if ((options.Transports & TransportType.WebSockets) != 0 && ServerHasWebSockets(context.Features))
            {
                response.AvailableTransports.Add(_webSocketAvailableTransport);
            }

            if ((options.Transports & TransportType.ServerSentEvents) != 0)
            {
                response.AvailableTransports.Add(_serverSentEventsAvailableTransport);
            }

            if ((options.Transports & TransportType.LongPolling) != 0)
            {
                response.AvailableTransports.Add(_longPollingAvailableTransport);
            }

            MemoryStream ms = new MemoryStream();

            NegotiateProtocol.WriteResponse(response, ms);

            return(ms.ToArray());
        }
        private static void WriteNegotiatePayload(IBufferWriter <byte> writer, string connectionId, HttpContext context, HttpConnectionOptions options)
        {
            var response = new NegotiationResponse();

            response.ConnectionId        = connectionId;
            response.AvailableTransports = new List <AvailableTransport>();

            if ((options.Transports & HttpTransportType.WebSockets) != 0 && ServerHasWebSockets(context.Features))
            {
                response.AvailableTransports.Add(_webSocketAvailableTransport);
            }

            if ((options.Transports & HttpTransportType.ServerSentEvents) != 0)
            {
                response.AvailableTransports.Add(_serverSentEventsAvailableTransport);
            }

            if ((options.Transports & HttpTransportType.LongPolling) != 0)
            {
                response.AvailableTransports.Add(_longPollingAvailableTransport);
            }

            NegotiateProtocol.WriteResponse(response, writer);
        }