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


C# WebSocket.Connect方法代码示例

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


在下文中一共展示了WebSocket.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: button1_Click

 private void button1_Click(object sender, EventArgs e)
 {
     ws = new WebSocket("ws://localhost:8080/?id=" + txtName.Text);
     ws.OnOpen += new EventHandler(ws_OnOpen);
     ws.OnMessage += new EventHandler<MessageEventArgs>(ws_OnMessage);
     ws.OnError += new EventHandler<ErrorEventArgs>(ws_OnError);
     ws.OnClose += new EventHandler<CloseEventArgs>(ws_OnClose);
     ws.Connect();
 }
开发者ID:XEonAX,项目名称:Grind,代码行数:9,代码来源:WebSocketClient.cs

示例8: ConnectWebSocket

        public void ConnectWebSocket(string Address)
        {
            Socket = new WebSocket(Address, "connection");
            Socket.OnOpen += ServerToClientConnected;
            Socket.OnMessage += ServerToClientOnMessage;
            Socket.OnClose += ServerToClientDisconnected;

            Socket.Connect();
        }
开发者ID:SeongHoJu,项目名称:NodeJS_Client,代码行数:9,代码来源:WebConnect.cs

示例9: Main

        public static void Main(string[] args)
        {
            //using (WebSocket ws = new WebSocket("ws://localhost:8000/"))
              using (WebSocket ws = new WebSocket("ws://localhost:8000/", "chat"))
              {
            /*ws.OnOpen += (o, e) =>
            {
              //Do something.
            };
             */
            ws.OnMessage += (o, s) =>
            {
            #if NOTIFY
              Notification nf = new Notification("[WebSocket] Message",
                                             s,
                                             "notification-message-im");
              nf.AddHint("append", "allowed");
              nf.Show();
            #else
              Console.WriteLine("[WebSocket] Message: {0}", s);
            #endif
            };

            ws.OnError += (o, s) =>
            {
              Console.WriteLine("[WebSocket] Error  : {0}", s);
            };

            /*ws.OnClose += (o, e) =>
            {
              //Do something.
            };
             */
            ws.Connect();

            Thread.Sleep(500);
            Console.WriteLine("\nType \"exit\" to exit.\n");

            string data;
            while (true)
            {
              Thread.Sleep(500);

              Console.Write("> ");
              data = Console.ReadLine();
              if (data == "exit")
              {
            break;
              }

              ws.Send(data);
            }
              }
        }
开发者ID:jeremyong,项目名称:websocket-sharp,代码行数:54,代码来源:wsclient.cs

示例10: TestClient

        static void TestClient()
        {
            using (var ws = new WebSocket("ws://localhost:8080/test1"))
            {
                ws.OnMessage += (sender, e) =>
                  Console.WriteLine("Laputa says: " + e.Data);

                ws.Connect();
                ws.Send("BALUS");
                Console.ReadKey(true);
            }
        }
开发者ID:joelhoro,项目名称:JHLib,代码行数:12,代码来源:Program.cs

示例11: Connect

 public bool Connect(string url, string session)
 {
     socket = new WebSocket(url);
     socket.WaitTime = TimeSpan.FromSeconds(5);
     socket.OnOpen += Socket_OnOpen;
     socket.OnError += Socket_OnError;
     socket.OnMessage += Socket_OnMessage;
     socket.OnClose += Socket_OnClose;
     socket.Connect();
     reset.WaitOne();
     return IsConnected;
 }
开发者ID:ysjr-2002,项目名称:QuickDoor,代码行数:12,代码来源:KoalaSocket.cs

示例12: OpenClient

 public void OpenClient()
 {
     if (_client != null)
     {
         _client.OnMessage -= OnRecievedMessage;
         _client.OnError -= OnError;
         _client.Close();
     }
     _client = new WebSocket(Settings.Default.Url);
     _client.OnMessage += OnRecievedMessage;
     _client.OnError += OnError;
     _client.Connect();
 }
开发者ID:jz5,项目名称:Pronama-chan-WebSocketNotifierClient,代码行数:13,代码来源:MainForm.cs

示例13: InternalConnect

 public static void InternalConnect(String ipAddress)
 {
     try
     {
     webClient = new WebSocket("wss://" + ipAddress + ":3001");
     webClient.OnMessage += webClient_OnMessage;
     webClient.Connect();
     }
     catch (Exception ex)
     {
     Log.Error("Auto3D: " + ex.Message);
     }
 }
开发者ID:yartat,项目名称:Auto3D,代码行数:13,代码来源:WebOS.cs

示例14: Connect

        private void Connect(string url)
        {
            if (_webSocket != null)
            {
                _webSocket.Close();
                _webSocket.OnMessage -= OnSocketMessage;
                _webSocket.OnClose -= OnSocketClose;
                _webSocket = null;
            }

            _webSocket = new WebSocket(url);
            _webSocket.OnMessage += OnSocketMessage;
            _webSocket.OnClose += OnSocketClose;
            _webSocket.Connect();
        }
开发者ID:seanhussey,项目名称:windows-slack-notifier,代码行数:15,代码来源:RtmConnection.cs

示例15: WebSocketSharpServer

    public WebSocketSharpServer(ServerSettings settings) {
      Settings = settings;
      Server = new WebSocketServer(Settings.Port);
      BaseUri = new Uri($"ws://localhost:{Server.Port}");
      Server.Start();
      Server.AddWebSocketService<Heartbeat>($"/{HeartbeatEndpoint}");
      Heartbeat = new WebSocket($"{BaseUri}{HeartbeatEndpoint}");
      Heartbeat.Connect();

      Task.Factory.StartNew(() => {
        while (!_isDisposing) {
          Heartbeat.Send("Heartbeat OK");
          Task.Delay(5000).Wait();
        }
      });
    }
开发者ID:grrizzly,项目名称:eventsourced.net,代码行数:16,代码来源:WebSocketSharpServer.cs


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