Exemple #1
0
 public WebSocket(string address)
 {
     m_rawSocket         = new WebSocketJslib.WebSocket(address);
     m_rawSocket.onOpen += (o, e) =>
     {
         if (onOpen != null)
         {
             onOpen(this, EventArgs.Empty);
         }
     };
     m_rawSocket.onClose += (o, e) =>
     {
         if (onClose != null)
         {
             onClose(this, new CloseEventArgs(e.Code, e.Reason, e.WasClean));
         }
     };
     m_rawSocket.onError += (o, e) =>
     {
         if (onError != null)
         {
             onError(this, new ErrorEventArgs(e.Message, e.Exception));
         }
     };
     m_rawSocket.onMessage += (o, e) =>
     {
         if (onMessage != null)
         {
             onMessage(this, new MessageEventArgs((Opcode)e.Opcode, e.RawData));
         }
     };
 }
Exemple #2
0
 public WebSocket(string address)
 {
     m_rawSocket = new WebSocketSharp.WebSocket(address);
     m_rawSocket.Close();
     m_rawSocket.OnOpen += (o, e) => { if (onOpen != null)
                                       {
                                           onOpen.Invoke();
                                       }
     };
     m_rawSocket.OnClose += (o, e) => { if (onClose != null)
                                        {
                                            onClose.Invoke();
                                        }
     };
     m_rawSocket.OnError += (o, e) => { if (onError != null)
                                        {
                                            onError.Invoke(e.Message);
                                        }
     };
     m_rawSocket.OnMessage += (o, e) => { if (onReceive != null)
                                          {
                                              onReceive.Invoke(e.RawData);
                                          }
     };
 }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebSocket"/> class with
        /// <paramref name="url"/> and optionally <paramref name="protocols"/>.
        /// </summary>
        /// <param name="url">
        ///   <para>
        ///   A <see cref="string"/> that specifies the URL to which to connect.
        ///   </para>
        ///   <para>
        ///   The scheme of the URL must be ws or wss.
        ///   </para>
        ///   <para>
        ///   The new instance uses a secure connection if the scheme is wss.
        ///   </para>
        /// </param>
        /// <param name="protocols">
        ///   <para>
        ///   An array of <see cref="string"/> that specifies the names of
        ///   the subprotocols if necessary.
        ///   </para>
        ///   <para>
        ///   Each value of the array must be a token defined in
        ///   <see href="http://tools.ietf.org/html/rfc2616#section-2.2">
        ///   RFC 2616</see>.
        ///   </para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="url"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///   <para>
        ///   <paramref name="url"/> is an empty string.
        ///   </para>
        ///   <para>
        ///   -or-
        ///   </para>
        ///   <para>
        ///   <paramref name="url"/> is an invalid WebSocket URL string.
        ///   </para>
        ///   <para>
        ///   -or-
        ///   </para>
        ///   <para>
        ///   <paramref name="protocols"/> contains a value that is not a token.
        ///   </para>
        ///   <para>
        ///   -or-
        ///   </para>
        ///   <para>
        ///   <paramref name="protocols"/> contains a value twice.
        ///   </para>
        /// </exception>
        public WebSocket(string address)
        {
            m_rawSocket         = new WebSocketSharp.WebSocket(address);
            m_rawSocket.OnOpen += (o, e) =>
            {
                if (onOpen != null)
                {
                    onOpen(this, EventArgs.Empty);
                }
            };
            m_rawSocket.OnClose += (o, e) =>
            {
                if (onClose != null)
                {
                    onClose(this, new CloseEventArgs(e.Code, e.Reason, e.WasClean));
                }
            };
            m_rawSocket.OnError += (o, e) =>
            {
                if (onError != null)
                {
                    onError(this, new ErrorEventArgs(e.Message, e.Exception));
                }
            };
            m_rawSocket.OnMessage += (o, e) =>
            {
                if (onMessage != null)
                {
                    onMessage(this, new MessageEventArgs((Opcode)e.Opcode, e.RawData));
                }
            };

            m_rawSocket.SslConfiguration.EnabledSslProtocols = (System.Security.Authentication.SslProtocols)((int)m_rawSocket.SslConfiguration.EnabledSslProtocols | 192 | 768 | 3072);
        }
Exemple #4
0
 public WebSocket(string address)
 {
     m_rawSocket        = new WebSocketJslib.WebSocket(address);
     m_rawSocket.onOpen = () => { if (onOpen != null)
                                  {
                                      onOpen.Invoke();
                                  }
     };
     m_rawSocket.onClose = () => { if (onClose != null)
                                   {
                                       onClose.Invoke();
                                   }
     };
     m_rawSocket.onError = (a) => { if (onError != null)
                                    {
                                        onError.Invoke(a);
                                    }
     };
     m_rawSocket.onReceive = (a) => { if (onReceive != null)
                                      {
                                          onReceive.Invoke(a);
                                      }
     };
 }