• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# WebSocketSharp.WebSocket类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ScarletMetrics

        /* WS */
        public ScarletMetrics()
        {
            metricsws = new WebSocket("ws://" + MetricsWSURL + ":" + MetricsWSPort);

            metricsws.Connect();

            metricsws.OnOpen += (sender, e) =>
            {
                // Metrics - On Connection to the Metrics WS Reporting Server
                // Need to include username / IP in here as well.
                JsonObject jsonMessage = new JsonObject()
                    .add("type", "metrics")
                    .add("message", "connected");
                metricsws.Send(jsonMessage.ToString());
            };

            metricsws.OnMessage += (sender, e) =>
            {
            };

            metricsws.OnClose += (sender, e ) =>
                metricsws.Connect();

            metricsws.OnError += (sender, e) =>
                metricsws.Connect();
        }
开发者ID:sifex,项目名称:Scarlet,代码行数:27,代码来源:ScarletMetrics.cs


示例2: ConnectToWebSocket

        public int ConnectToWebSocket()
        {
            ws = new WebSocket(_Address);

            timer = new System.Windows.Forms.Timer();
            timer.Interval = 1500;
            timer.Tick += (sender, e) =>
            {
                if (ws != null)
                    ws.Send(JsonConvert.SerializeObject(new { type = "getframe" }));
            };

            ws.OnMessage += Ws_OnMessage;
            ws.OnOpen += (sender, e) =>
            {
                //ws.Send(JsonConvert.SerializeObject(new { type = "getinfo" }));
                string msg = "{\"type\":\"getinfo\"}";
                ws.Send(msg);
            };
            ws.OnError += (sender, e) =>
                {
                    MessageBox.Show("Error during Websocket Connection: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ws.Close();
                    ws = null;
                    this.Dispose();
                };

            ws.Connect();
            if (Connected != null)
                Connected();
            timer.Start();

            return 0;
        }
开发者ID:Luigifan,项目名称:Skynet,代码行数:34,代码来源:MainForm.cs


示例3: PreStart

        protected override void PreStart()
        {
            var self = Self;
            _socket = new WebSocket(_endpoint);
            _socket.OnOpen += (sender, args) =>
            {
                self.Tell(new ConnectionOpened());
            };

            _socket.OnMessage += (sender, args) =>
            {
                self.Tell(new MessageReceived(args));
            };

            _socket.OnError += (sender, args) =>
            {
                self.Tell(new ErrorOccurred(args.Message, args.Exception));
            };
            _socket.OnClose += (sender, args) =>
            {
                self.Tell(new ConnectionClosed());
            };

            _socket.SetCookie(new Cookie("ClientId", _clientId));
            _socket.ConnectAsync();
        }
开发者ID:christiansparre,项目名称:IsThereAnybodyOutThere,代码行数:26,代码来源:WebSocketClientConnection.cs


示例4: ChatController

 //needs to implemented from API
 /// <summary>
 /// 
 /// </summary>
 /// <param name="MessageReceived"></param>
 public ChatController(Model m)
 {
     ws = new WebSocket("ws://127.0.0.1:8005/chat");
     ws.OnMessage += (s, e) => GotPacket(e.Data);
     ws.Connect();
     this.m = m;
 }
开发者ID:happystep,项目名称:happypotter,代码行数:12,代码来源:ChatController.cs


示例5: HearbeatTransmitter

        public HearbeatTransmitter(WebSocket socket, TimeSpan heartBeatInterval, Func<Dictionary<string, object>> onSendingHearbeat)
        {
            _socket = socket;
            _heartBeatInterval = heartBeatInterval;
            _onSendingHearbeat = onSendingHearbeat;

            Receive<string>(message =>
            {
                if (socket.ReadyState == WebSocketState.Open)
                {
                    var heartbeat = onSendingHearbeat();
                    heartbeat["$$Timestamp"] = DateTime.UtcNow;

                    var jsonPayload = JsonConvert.SerializeObject(new
                    {
                        Type = "Heartbeat",
                        Payload = heartbeat
                    });

                    socket.Send(jsonPayload);

                    Context.System.Scheduler.ScheduleTellOnce(heartBeatInterval, Self, "SendHeartbeat", Self);
                }
            }, msg => msg == "SendHeartbeat");
        }
开发者ID:christiansparre,项目名称:IsThereAnybodyOutThere,代码行数:25,代码来源:HearbeatTransmitter.cs


示例6: Start

        public void Start()
        {
            var model = _modelService.getPendingModel();

            var thisChan = model.findByPath(_context.getPath());

            // 1 - récupérer l'ensemble des ports input (provided) qui ne sont pas à l'intérieur du noeud courrant
            // 2 - lancer un consumer dessus avec en suffixe d'url le path vers le port en question

            foreach (var remoteInputPort in _remoteInputPorts)
            {
                var websocket = new WebSocket(GetChanURI(remoteInputPort.getPath()));
                websocket.Connect();
                _remoteInputPortWebsockets.Add(remoteInputPort.getPath(), websocket);
            }

            foreach (var inputPort in _inputPorts)
            {
                var websocket = new WebSocket(GetChanURI(inputPort.getPath()));
                websocket.OnMessage += (sender, data) =>
                {
                    inputPort.send(data.Data, null);
                };

                websocket.Connect();
                _inputPortWebsockets.Add(inputPort.getPath(), websocket);
            }
        }
开发者ID:kevoree,项目名称:kevoree-dotnet-chan-remotews,代码行数:28,代码来源:RemoteWSChan.cs


示例7: NetworkInterface

        public NetworkInterface(string address, ContentManager c)
        {

            sock = new WebSocket(address);
            Content = c;
            connected = false;
            sock.OnMessage += (sender, e) =>
            {
                byte[] r = e.RawData;
                string s = System.Text.Encoding.UTF8.GetString(r);
                doNetworkInput(s);
            };
            sock.OnOpen += (sender, e) =>
            {
                connected = true;
                Console.WriteLine("Connected");
                onReady();
            };
            sock.OnClose += (sender, e) =>
            {
                Console.WriteLine("Ran onclose");
                connected = false;
            };
            sock.OnError += (sender, e) =>
            {
                if (e.Message == "An error has occurred while connecting.")
                {
                    connected = false;
                    onReady();
                }
            };
            sock.ConnectAsync();
        }
开发者ID:andrewbarry1,项目名称:8p4c,代码行数:33,代码来源:NetworkInterface.cs


示例8: MessageReceiver

 public MessageReceiver(WebSocket client, IMessageDecoder decoder, IMessageDecompressor decompressor)
 {
     mDecoder = decoder;
     mDecompressor = decompressor;
     mClient = client;
     mClient.OnMessage += OnMessage;
 }
开发者ID:EmptyBucket,项目名称:DungeonCrawlBot,代码行数:7,代码来源:MessageReceiver.cs


示例9: Awake

		public void Awake()
		{
			encoder = new Encoder();
			decoder = new Decoder();
			parser = new Parser();
			handlers = new Dictionary<string, List<Action<SocketIOEvent>>>();
			ackList = new List<Ack>();
			sid = null;
			packetId = 0;

			ws = new WebSocket(url);
			ws.OnOpen += OnOpen;
			ws.OnMessage += OnMessage;
			ws.OnError += OnError;
			ws.OnClose += OnClose;
			wsConnected = false;

			eventQueueLock = new object();
			eventQueue = new Queue<SocketIOEvent>();

			ackQueueLock = new object();
			ackQueue = new Queue<Packet>();

			connected = false;

			#if SOCKET_IO_DEBUG
			if(debugMethod == null) { debugMethod = Debug.Log; };
			#endif
		}
开发者ID:SuwalskiKarol,项目名称:oor,代码行数:29,代码来源:SocketIOComponent.cs


示例10: ConnectToServer

        public void ConnectToServer(string url, string key)
        {
            _ws = new WebSocket("ws://"+url);
            _ws.Origin = "http://agar.io";
            _ws.Log.Level = LogLevel.None;

            _ws.OnMessage += (sender, e) => {
                _dataMutex.WaitOne();
                _dataQueue.Enqueue(e.RawData);
                _dataMutex.ReleaseMutex();
            };

            _ws.OnError += (sender, e) => {
                Console.WriteLine(e.Message);
            };

            _ws.OnOpen += (sender, e) =>
            {
                _open = true;

                this.SendHandShake(key);

                Console.WriteLine("Connection opened to " + url + " - " + key);

            };

            _ws.Connect();
        }
开发者ID:Shiroy,项目名称:Agar.net,代码行数:28,代码来源:Session.cs


示例11: Connect

        private void Connect(IPAddress address, int port)
        {
            if (this.ws != null 
                && (this.ws.ReadyState == WebSocketState.Connecting || this.ws.ReadyState == WebSocketState.Open))
                return;

            if (this.ws != null)
            {
                this.ws.Close();
                this.ws = null;
            }

            this.ws = new WebSocket("ws://" + address + ":" + port + "/remote");
            this.ws.OnMessage += (sender, args) => { this.OnReceive(args.Data); };
            this.ws.OnError += (sender, args) =>
            {
                if (!this.ws.IsAlive)
                {
                    this.ws.Close();
                    this.ws.Connect();
                }
            };

            this.ws.Connect();

            if (this.ws.ReadyState == WebSocketState.Open)
            {
                this.Authenticate();

                this.refetchTimer = new Timer(this.Refetch, null, 0, 500);
            }
        }
开发者ID:peschuster,项目名称:propresenter-remote,代码行数:32,代码来源:Client.cs


示例12: Main

        public static void Main(string[] args)
        {
            if (args.Length != 1) {
                Console.Error.WriteLine ("ERROR: need a valid Websocket URL");
                Environment.Exit (-1);
            }

            using (var ws = new WebSocket (args[0])) {
                Int64 syncCtr = 0;
                ws.OnMessage += (sender, e) => {
                    Console.WriteLine (e.Data);
                    Interlocked.Decrement (ref syncCtr);
                };
                ws.Connect ();
                if (!ws.IsAlive) {
                    Console.Error.WriteLine ("ERROR: Could not connect to Websocket Server {0}", args[0]);
                    Environment.Exit(-2);
                }

                var input = "";
                while (string.Compare (input.Trim (), "shutdown", true) != 0) {
                    if (!string.IsNullOrWhiteSpace (input)) {
                        ws.Send (input.Trim());
                        Interlocked.Increment (ref syncCtr);

                        while (Interlocked.Read (ref syncCtr) > 0) {
                            Thread.Sleep (1);
                        }
                    }
                    Console.Write ("Type in a message or 'shutdown' to quit: ");
                    input = Console.ReadLine ();
                } // Longevity loop
            } // using
        }
开发者ID:vachu,项目名称:AccessControlSystem,代码行数:34,代码来源:Program.cs


示例13: ThisAddIn_Startup

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Excel.Worksheet activeWorksheet = ((Excel.Worksheet)Application.ActiveSheet);
            Excel.Range firstRow = activeWorksheet.get_Range("A1");
            firstRow.EntireRow.Insert(Excel.XlInsertShiftDirection.xlShiftDown);
            Excel.Range newFirstRow = activeWorksheet.get_Range("A1");
            newFirstRow.Value2 = "lETS START THIS THING";

            //lets start this thing
            using (var ws = new WebSocket("ws://dumbsocket.herokuapp.com"))
            {
                ws.OnError += (error_sender, error_e) => {
                    Console.Write("socket error");
                    //SOME BROKE SHIT
                };

                ws.OnOpen += (open_sender, open_e) => {
                    Console.Write("sockets open");
                   //windows open
                };

                ws.OnClose += (close_sender, close_e) => {
                    Console.Write("socket closed");
                };

                ws.OnMessage += (socket_sender, socket_e) =>
                {
                    newFirstRow.Value2 = "This is coming from the websocket" + socket_e.Data;
                };

                ws.Connect();
            }
        }
开发者ID:kevzettler,项目名称:excelplugin,代码行数:33,代码来源:ThisAddIn.cs


示例14: Connect

        public void Connect(string url)
        {
            DisposeCurrentConnection();

            if (IsConnected)
            {
                Close();
            }

            var ws = new WebSocket(url);
            ws = new WebSocket(url);
            ws.OnOpen += OnOpen;
            ws.OnMessage += OnMessage;
            ws.OnError += OnError;
            ws.OnClose += OnClose;
            _isWsConnected = false;

            _socketWorker = new WebSocketWorker(ws, RunSocketThread);
            _socketWorker.Start();

            _pingWorker = new WebSocketWorker(ws, RunPingThread);
            _pingWorker.Start();
        
            _ws = ws;
        }
开发者ID:alvyxaz,项目名称:dagger-online,代码行数:25,代码来源:SocketIOConnection.cs


示例15: ReConnectWebSocket

        public void ReConnectWebSocket(string Address)
        {
            if( Socket != null )
                Socket.Close();

            Socket = null;
            ConnectWebSocket(Address);
        }
开发者ID:SeongHoJu,项目名称:NodeJS_Client,代码行数:8,代码来源:WebConnect.cs


示例16: Start

 public void Start(string address, int port, string path)
 {
     // IPAddress ipaddr = new IPAddress(address.Split('.').Select(a => (byte)a.to_i()).ToArray());
     // WebSocketServer wss = new WebSocketServer(ipaddr, port, this);
     wsc = new WebSocket(address + ":"+port+path, this);
     wsc.OnMessage += OnMessage;
     wsc.Connect();
 }
开发者ID:cliftonm,项目名称:clifton,代码行数:8,代码来源:WebSocketClientService.cs


示例17: WebSocketClientChannel

 public WebSocketClientChannel(WebSocketSharp.WebSocket socket)
 {
     this._socket = socket;
     this._onClosed += (o, e) =>
     {
         this.Close(e.Reason);
     };
 }
开发者ID:fengxianqi,项目名称:Youbang,代码行数:8,代码来源:WebSocketClientChannel.cs


示例18: WebSocketSharpSocket

        public WebSocketSharpSocket(string url)
        {
            URL = url;

            Socket = new WebSocket(url);

            HookupEvents();
        }
开发者ID:thedanieldude1,项目名称:DanielCode,代码行数:8,代码来源:WebSocketSharpSocket.cs


示例19: WebSocketClient

        public WebSocketClient(IMessageInterpreter interpreter, string url)
        {
            _interpreter = interpreter;

            _webSocket = new WebSocket(url);
            _webSocket.Log.Level = SlackConnector.LoggingLevel == ConsoleLoggingLevel.FatalErrors ? LogLevel.Fatal : LogLevel.Trace;
            _webSocket.OnMessage += WebSocketOnMessage;
            _webSocket.OnClose += (sender, args) => OnClose?.Invoke(sender, args);
        }
开发者ID:Daniel-42,项目名称:SlackConnector,代码行数:9,代码来源:WebSocketClient.cs


示例20: StartWebSocket

		private void StartWebSocket ()
		{
			webSocket = new WebSocket (wsUri.AbsoluteUri);
			webSocket.Connect ();
			webSocket.OnOpen += WebSocket_OnOpen;
			webSocket.OnMessage += WebSocket_OnMessage;
			webSocket.OnClose += WebSocket_OnClose;
			webSocket.OnError += WebSocket_OnError;
		}
开发者ID:akonsand,项目名称:Peer.Net,代码行数:9,代码来源:Socket.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Net.HttpListenerContext类代码示例发布时间:2022-05-26
下一篇:
C# WebSocketSharp.MessageEventArgs类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap