当前位置: 首页>>代码示例>>C#>>正文


C# WebSocket4Net.WebSocket类代码示例

本文整理汇总了C#中WebSocket4Net.WebSocket的典型用法代码示例。如果您正苦于以下问题:C# WebSocket类的具体用法?C# WebSocket怎么用?C# WebSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WebSocket类属于WebSocket4Net命名空间,在下文中一共展示了WebSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChatHandler

 public ChatHandler(RichTextBox messageList, RichTextBox roomMessageList)
 {
     this.messageList = messageList;
     this.roomMessageList = roomMessageList;
     websocket = new WebSocket("ws://" + ClientBase.serverAdress + PORT_ROUTE);
     websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(receiveChat);
     websocket.Open();
 }
开发者ID:Cir0X,项目名称:ludo,代码行数:8,代码来源:ChatHandler.cs

示例2: MainWindow

 public MainWindow()
 {
     InitializeComponent();
     if (serverURL == "")
     {
         textBox1.Text = "[エラー]";
         textBox2.Text = "[エラー]\n";
         textBox2.Text += " サーバのURLを講義担当者から聞いてserverURL変数にセットしてください\n";
     }
     else
     {
         websocket = new WebSocket(serverURL);
         websocket.Closed += new EventHandler(websocket_Closed);
         websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
         websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);
         websocket.Opened += new EventHandler(websocket_Opened);
         textBox2.Text += "[使い方]\n";
         textBox2.Text += " 上のテキストボックスに入力しenterか送信ボタンでサーバへ送信されます。\n";
         textBox2.Text += " サーバは得たデータの先頭に'Server said'と付けて、そのまま返します。\n";
         textBox2.Text += " サーバから帰って来た文字列がこのテキストボックスに表示されます。\n";
         textBox2.Text += " 発言の先頭に「all:」を付けて送信すると、サーバに接続している全員に送られます。\n";
         textBox2.Text += "[init]\n";
         textBox1.Focus();
         websocket.Open();
     }
 }
开发者ID:xskogure,项目名称:websocket4net-example,代码行数:26,代码来源:MainWindow.xaml.cs

示例3: FetchConnections

 public void FetchConnections()
 {
     if (!_isConnected)
         throw new Exception("Not connected");
     _socket = new WebSocket("wss://www.irccloud.com/", "", _cookies, null, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", "https://www.irccloud.com");
     _socket.MessageReceived += socket_MessageReceived;
     _socket.Open();
 }
开发者ID:headswe,项目名称:irccloudNET,代码行数:8,代码来源:IrcClient.cs

示例4: OnlineUserHandler

 //Object syncLock = new Object();
 public OnlineUserHandler(ListView onlineUserList)
 {
     this.onlineUserList = onlineUserList;
     websocket = new WebSocket("ws://" + ClientBase.serverAdress + PORT_ROUTE);
     websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(handleOnlineUsers);
     websocket.Open();
 }
开发者ID:Cir0X,项目名称:ludo,代码行数:8,代码来源:OnlineUserHandler.cs

示例5: Connect

        public void Connect(string url)
        {
            Uri uri = null;

            string connectionId = Strings.RandomString(8);
            int serverId = Strings.RandomNumber(1, 1000);

            try
            {
                uri = new Uri(url);
            }
            catch (Exception)
            {
                throw new OrtcEmptyFieldException(String.Format("Invalid URL: {0}", url));
            }

            string prefix = uri != null && "https".Equals(uri.Scheme) ? "wss" : "ws";

            Uri connectionUrl = new Uri(String.Format("{0}://{1}:{2}/broadcast/{3}/{4}/websocket", prefix, uri.DnsSafeHost, uri.Port, serverId, connectionId));

            //
            // NOTE: For wss connections, must have a valid installed certificate
            // See: http://www.runcode.us/q/c-iphone-push-server
            //

            _websocket = new WebSocket(connectionUrl.AbsoluteUri);

            _websocket.Opened += new EventHandler(websocket_Opened);
            _websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
            _websocket.Closed += new EventHandler(websocket_Closed);
            _websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);

            _websocket.Open();
        }
开发者ID:l0hn,项目名称:RealtimeMessaging-dotnet,代码行数:34,代码来源:WebSocketConnection.cs

示例6: RpcClient

        public RpcClient(string ip, int port)
        {
            var uri = string.Format("ws://{0}:{1}/", ip, port);

            _client = new WebSocket(uri);
            _client.NoDelay = true;

            _client.Opened += (sender, args) =>
                Task.Run(() => DispatchConnected());

            _client.Closed += (sender, args) =>
                Task.Run(() => SafeCall(DispatchDisconnected));

            Send = message => SafeCall(() =>
            {
                var data = RpcMessage.Write(message);
                _client.Send(data);
            });

            _client.MessageReceived += (sender, args) => SafeCall(() =>
            {
                var data = args.Message;
                var message = RpcMessage.Read(data);
                Task.Run(() => ProcessMessage(message));
            });

            Task.Run(() => SafeCall(_client.Open));
        }
开发者ID:Rohansi,项目名称:Rohmote,代码行数:28,代码来源:RpcClient.cs

示例7: Connect

        public Task Connect(string host, CancellationToken cancelToken)
        {
            try
            {
                _webSocket = new WebSocketClient(host);
                _webSocket.EnableAutoSendPing = false;
                _webSocket.NoDelay = true;
                _webSocket.Proxy = null;

                _webSocket.DataReceived += OnWebSocketBinary;
                _webSocket.MessageReceived += OnWebSocketText;
                _webSocket.Error += OnWebSocketError;
                _webSocket.Closed += OnWebSocketClosed;
                _webSocket.Opened += OnWebSocketOpened;

                _waitUntilConnect.Reset();
                _waitUntilDisconnect.Reset();
                _webSocket.Open();
                _waitUntilConnect.Wait(cancelToken);
                _taskManager.ThrowException(); //In case our connection failed
            }
            catch
            {
                _waitUntilDisconnect.Set();
                throw;
            }
            return TaskHelper.CompletedTask;
        }
开发者ID:ElAfroNinja,项目名称:Discord.Net,代码行数:28,代码来源:WS4NetEngine.cs

示例8: MainWindow

        public MainWindow()
        {
            InitializeComponent();
            if (serverURL == "")
            {
                textBox1.Text = "URL不明!";
            }
            else
            {
                textBox1.Text = channel;
                websocket = new WebSocket(serverURL);
                websocket.Closed += new EventHandler(websocket_Closed);
                websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
                websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);
                websocket.Opened += new EventHandler(websocket_Opened);
                websocket.Open();

                InitializeComponent(); // aaa
                //Kinectの初期化
                kinect = KinectSensor.KinectSensors[0];
                //イベントハンドラの登録
                kinect.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(handler_SkeletonFrameReady);
                //骨格トラッキングの有効化
                kinect.SkeletonStream.Enable();
                kinect.Start(); // aaa
            }
        }
开发者ID:cs09072,项目名称:gsSlider,代码行数:27,代码来源:MainWindow.xaml.cs

示例9: Connect

        public void Connect(string url)
        {
            if (_url == string.Empty)
                _url = "ws://" + url + "/websocket";

            if (_socket == null)
            {
                Console.WriteLine("Creating WebSocket...");
                _socket = new WebSocket(_url);

                _socket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(socket_MessageReceived);
                _socket.Opened += new EventHandler(_socket_Opened);
                _socket.Closed += new EventHandler(_socket_Closed);
                _socket.Error += _socket_Error;
            }

            Console.WriteLine("Connecting...");

            //_socket.AutoSendPingInterval = 30;
            //_socket.EnableAutoSendPing = true;

            if (!isConnected && _socket.State != WebSocketState.Open)
            {
                _socket.Open();
                _isWait = 1;
                this.Wait();
            }
            Console.WriteLine("Connected.");
            this._client.OnConnected();
        }
开发者ID:aaronthorp,项目名称:net-meteor-ddp-client,代码行数:30,代码来源:DDPConnector.cs

示例10: RippleApi

        internal RippleApi(IConfiguration config, ILogger logger, IFeeProvider feeProvider, ITransactionSigner txSigner, string dataApiUrl, string exchIssuerAddress, string fiatCurrencyCode)
        {
            _config = config;
            _logger = logger;
            _feeProvider = feeProvider;
            _txSigner = txSigner;
            _dataApiUrl = dataApiUrl;
            _issuerAddress = exchIssuerAddress;
            _fiatCurreny = fiatCurrencyCode;
            _walletAddress = _config.AccessKey;

            _webSocket = new WebSocket(_rippleSocketUri = _config.GetValue("server"));

            string proxyHost = _config.GetValue("proxyHost");
            string proxyPort = _config.GetValue("proxyPort");
            if (null != proxyHost && null != proxyPort)
            {
                //TODO: these two lines don't belong here, rather to WebClient2
                _webProxy = new WebProxy(proxyHost, int.Parse(proxyPort));
                _webProxy.Credentials = CredentialCache.DefaultCredentials;

                var wsProxy = new HttpConnectProxy(new DnsEndPoint(proxyHost, Int32.Parse(proxyPort)), "1.0");
                _webSocket.Proxy = wsProxy;
            }

            _webSocket.Opened += websocket_Opened;
            _webSocket.Error += websocket_Error;
            _webSocket.Closed += websocket_Closed;
            _webSocket.MessageReceived += websocket_MessageReceived;
        }
开发者ID:rarach,项目名称:exchange-bots,代码行数:30,代码来源:RippleApi.cs

示例11: FchatService

        /// <summary>
        ///     Initializes a new instance of the <see cref="FchatService" /> class.
        ///     Chat connection is used to communicate with F-Chat using websockets.
        /// </summary>
        /// <param name="user">
        ///     The user.
        /// </param>
        /// <param name="eventagg">
        ///     The eventagg.
        /// </param>
        /// <param name="socket"></param>
        /// <param name="provider"></param>
        public FchatService(IAccount user, IEventAggregator eventagg, WebSocket socket, ITicketProvider provider)
        {
            this.socket = socket;
            this.provider = provider;
            Account = user.ThrowIfNull("user");
            events = eventagg.ThrowIfNull("eventagg");

            events.GetEvent<CharacterSelectedLoginEvent>()
                .Subscribe(ConnectToChat, ThreadOption.BackgroundThread, true);

            errsThatDisconnect = new[]
                {
                    Constants.Errors.NoLoginSlots,
                    Constants.Errors.NoServerSlots,
                    Constants.Errors.KickedFromServer,
                    Constants.Errors.SimultaneousLoginKick,
                    Constants.Errors.BannedFromServer,
                    Constants.Errors.BadLoginInfo,
                    Constants.Errors.TooManyConnections,
                    Constants.Errors.UnknownLoginMethod
                };

            InitializeLog();

            autoPingTimer.Elapsed += (s, e) => TrySend(Constants.ClientCommands.SystemPing);
            autoPingTimer.Start();

            staggerTimer = new Timer(GetNextConnectDelay()); // first reconnect is 5 seconds
            staggerTimer.Elapsed += (s, e) => DoReconnect();
        }
开发者ID:Khayde,项目名称:slimCat,代码行数:42,代码来源:F-ChatConnection.cs

示例12: Connect

        void Connect(int times=3)
        {
            if (times > 0)
            {
                try
                {
                    _socketInstance = new WebSocket(_serverAddress);

                    _socketInstance.Opened += _socketInstance_Opened;
                    _socketInstance.Closed += _socketInstance_Closed;

                    _socketInstance.DataReceived += _socketInstance_DataReceived;
                    _socketInstance.Error += _socketInstance_Error;

                    _socketInstance.Open();
                }
                catch (System.Exception e)
                {
                    _dispatcher.LogException(e);
                    _dispatcher.LogWarning("Connect Failed! Try again 3 seconds later!");
                    Connect(times - 1);
                }
            }
            else
            {
                _dispatcher.Quit();
            }
        }
开发者ID:wsycarlos,项目名称:ARIA,代码行数:28,代码来源:NetHandler.cs

示例13: Connect

        public void Connect()
        {
            String url;

            if (String.IsNullOrEmpty(Port) ||
                String.IsNullOrEmpty(Domain))
                return;

            url = String.Format("ws://{0}:{1}{2}", Domain, Port, Path);

            try
            {

                socket = new WebSocket(
                    url,
                    "",
                    Cookies,
                    null,
                    null,
                    "http://" + Domain,
                    WebSocketVersion.DraftHybi10
                    );
                socket.Opened += new EventHandler(socket_Opened);
                socket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(socket_MessageReceived);
                socket.Closed += new EventHandler(socket_Closed);
                socket.Open();
            }
            catch (Exception e)
            {
                Debug.Print(String.Format("Websocket connection failed. {0} {1}", url, e.Message));
            }
        }
开发者ID:jfarre20,项目名称:Ubiquitous,代码行数:32,代码来源:UbiWebSocket.cs

示例14: Connect

 public void Connect(string uri)
 {
     this.socket = new WebSocket4Net.WebSocket(uri);
     this.socket.MessageReceived += this.SocketMessageReceived;
     this.socket.Closed += this.SocketClosed;
     this.socket.Open();
 }
开发者ID:meungblut,项目名称:Websockets,代码行数:7,代码来源:WebSocket4NetSocketClient.cs

示例15: Start

        public void Start()
        {
            if (_ws != null) return;

            string wsUrl;
            if (!string.IsNullOrEmpty(_symbol))
            {
                wsUrl = string.Format("wss://www.stockfighter.io/ob/api/ws/{0}/venues/{1}/tickertape/stocks/{2}", _account, _venue, _symbol);
            }
            else
            {
                wsUrl = string.Format("wss://www.stockfighter.io/ob/api/ws/{0}/venues/{1}/tickertape", _account, _venue);
            }

            _ws = new WebSocket(wsUrl);
            _ws.MessageReceived += MessageReceived;
            _ws.Opened += (s, e) => { if (Started != null) Started(this, EventArgs.Empty); };
            _ws.Error += (s, e) => { if (ErrorOccured != null) ErrorOccured(this, e.Exception.Message); };
            _ws.Closed += (s, e) =>
            {
                if (Stopped != null) Stopped(this, EventArgs.Empty);
                if (_reconnect) _ws.Open();
            };            
            
            _ws.Open();

        }
开发者ID:pb8,项目名称:Stockfighter,代码行数:27,代码来源:QuotesFeed.cs


注:本文中的WebSocket4Net.WebSocket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。