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


C# WebSocket.Connect方法代码示例

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


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

示例1: Start

    /// <summary>
    /// Start the Birb Client.
    /// </summary>
    /// <returns>Nothing right now.</returns>
    IEnumerator Start()
    {
        gameStateManager = GetComponent<GameStateManager>();
        Uri server = new Uri("ws://birb.herokuapp.com");
        Uri localhost = new Uri("ws://localhost:5000");
        socket = new WebSocket(server);
        callbacks = new Dictionary<BirbMessageCode, Callback>();
        yield return StartCoroutine(socket.Connect());
        int i = 0;

        // Testing
        //RunUnitTests();

        while (true)
        {
            string reply = socket.RecvString();
            if (reply != null)
            {
                Debug.Log("Received: " + reply);
                Process(reply);
            }
            if (socket.Error != null)
            {
                Debug.LogError("Error: " + socket.Error);
                break;
            }
            yield return 0;
        }
        socket.Close();
    }
开发者ID:UpBeet,项目名称:mating-ritual-client,代码行数:34,代码来源:BirbClient.cs

示例2: Connect

    void Connect()
    {
        ws =  new WebSocket("ws://socket.nappers.jp:8888");

        // called when websocket messages come.
        ws.OnMessage += (sender, e) =>
        {
            string s = e.Data;
            Debug.Log(string.Format( "Receive {0}",s));
            messages.Add("> " + e.Data);
            if(messages.Count > 10){
                messages.RemoveAt(0);
            }
        };

        ws.OnError += (sender, e) =>
        {
            Debug.Log("OnError");
        };
        ws.OnClose += (sender, e) =>
        {
            Debug.Log("OnClose");

        };
        ws.OnOpen += (sender, e) =>
        {
            Debug.Log("OnOpen");

        };

        ws.Connect();
        Debug.Log("Connect to " + ws.Url);
    }
开发者ID:ryuusinnca,项目名称:unity_socketIO,代码行数:33,代码来源:Chat.cs

示例3: Start

	// Use this for initialization
	IEnumerator Start () {
		WebSocket w = new WebSocket(new Uri("ws://127.0.0.1:8080/websocket"));
		yield return StartCoroutine(w.Connect());

		int i = 0;
		w.SendString(PackMessage("Hi there", i));
		while (true)
		{
			string reply = w.RecvString();
			if (reply != null)
			{
				Message msg = UnpackMessage (reply);
				Debug.Log ("Received: " + msg.msg + ", " + msg.no);
				w.SendString (PackMessage ("Hi there", i));
			}
			if (w.error != null)
			{
				Debug.LogError ("Error: " + w.error);
				break;
			}

			++i;

			yield return 0;
		}
		w.Close();
	}
开发者ID:rex8312,项目名称:WebsocketExample,代码行数:28,代码来源:EchoTest.cs

示例4: InitWebSocket

 void InitWebSocket()
 {
     _ws = new WebSocket ("wss://echo.websocket.org/");
     _ws.OnMessage += MessageCallback;
     _ws.OnError += ErrorCallback;
     _ws.Connect ();
 }
开发者ID:oldones,项目名称:app2pence,代码行数:7,代码来源:WebSocketImpl.cs

示例5: Connect

    // -----------------------------------------------------------------
    /// <summary>
    ///
    /// </summary>
    void Connect()
    {
        ws = new WebSocket (WSAddress);

        ws.OnOpen += (sender, e) => {
            Debug.Log ("<color=lime>WebSocket Open</color>");
        };

        ws.OnMessage += (sender, e) => {

            lock (messageQueue.SyncRoot) {
                try {
                    messageQueue.Enqueue (e.Data.ToString ());
                } catch (System.Exception ex) {
                    Debug.Log (ex.ToString ());
                }
            }

            //Debug.Log ("<color=cyan>WebSocket Message Type: " + e.Type + ", Data: " + e.Data + "</color>");
        };

        ws.OnError += (sender, e) => {
            Debug.Log ("<color=red>WebSocket Error Message: " + e.Message + "</color>");
        };

        ws.OnClose += (sender, e) => {
            Debug.Log ("<color=orange>WebSocket Close</color>");
        };

        ws.Connect ();
    }
开发者ID:nmbakfm,项目名称:hachitaiTeamLab,代码行数:35,代码来源:WebSocketClient.cs

示例6: Play

        public void Play()
        {
            var uri = new Uri(Server + "?user=" + Uri.EscapeDataString(UserName));

            using (var socket = new WebSocket(uri))
            {
                socket.Connect();

                while (!ShouldExit)
                {
                    var response = socket.Recv();

                    if (!response.StartsWith(ResponsePrefix))
                    {
                        Console.WriteLine("Something strange is happening on the server... Response:\n{0}", response);
                        ShouldExit = true;
                    }
                    else
                    {
                        var boardString = response.Substring(ResponsePrefix.Length);

                        var action = DoMove(new GameBoard(boardString));

                        socket.Send(action);
                    }
                }
            }
        }
开发者ID:alhenk,项目名称:snake,代码行数:28,代码来源:BombermanBase.cs

示例7: Connect

    void Connect()
    {
        //接続
        //ポートの指定はしなくても大丈夫だった。80で接続してるはず。
        ws =  new WebSocket(url);

        ws.OnOpen += (sender, e) => {
            //接続したら自分を制御用PCとしてサーバーに教える
            //SendSetPCMessage();
            print("Connected");
        };
        ws.OnMessage += (sender, e) => {
            string s = e.Data;
            //Debug.Log (s);
            Dictionary<string, object> dict = Json.Deserialize (s) as Dictionary<string, object>;
            //Debug.Log (dict["power"].GetType() );
            long val = (long)dict["power"];
            //Debug.Log ("val="+val);
            toColor = GetColor(val/divBy);

            value =  val/divBy;
        };
        ws.Connect();

        ws.OnClose += (sender, e) => {
            print("Closed");
        };

        ws.OnError += (sender, e) => {
            print("Error : " + e.Message);
        };
    }
开发者ID:shinobushiva,项目名称:Takeakari-System,代码行数:32,代码来源:WebSocketConnect.cs

示例8: Start

        IEnumerator Start()
        {
            _game = gameObject.GetComponent<MainProxy>();

            _state = ConnectionState.UNKNOWN;
            _socket = new WebSocket (new Uri ("ws://188.242.130.83:3000/echo"));
            yield return StartCoroutine (_socket.Connect ());
        }
开发者ID:andi2,项目名称:ld32-6,代码行数:8,代码来源:Connection.cs

示例9: WebtestClient

    public WebtestClient(string port)
    {
        client = new WebSocket(@"ws://127.0.0.1:" + port + "/Simulator");
        client.Connect();

        client.OnError += (sender, e) =>
              Debug.Log("error: " + e.Message.ToString());
        client.OnClose += (sender, e) =>
            Debug.Log("client on closing");
    }
开发者ID:CalleP,项目名称:BWC-simulator,代码行数:10,代码来源:WebtestClient.cs

示例10: Connect

    public void Connect(string playerName, string url)
    {
        PlayerName = playerName;

        if (Socket != null)
            Disconnect();

        Socket = new WebSocket(new Uri(url));
        StartCoroutine(Socket.Connect());
    }
开发者ID:Trainfire,项目名称:Drawesome,代码行数:10,代码来源:Connection.cs

示例11: PongWebSockets

    public PongWebSockets(string WebSocketServerAddress)
    {
        //nf = new Notifier();
        ws = new WebSocket(WebSocketServerAddress);

        ws.OnMessage += Ws_OnMessage;
        ws.OnOpen += Ws_OnOpen;
        ws.OnClose += Ws_OnClose;
        ws.OnError += Ws_OnError;
        ws.Connect();
    }
开发者ID:BahuMan,项目名称:MultiPong,代码行数:11,代码来源:PongWebSockets.cs

示例12: Connect

    void Connect()
    {
        ws =  new WebSocket("ws://localhost:8888/");

        // called when websocket messages come.
        ws.OnMessage += (sender, e) =>
        {
            /*
            string s = e.Data;
            Debug.Log(string.Format( "Receive {0}",s));
            messages.Add("> " + e.Data);
            if(messages.Count > 10){
                messages.RemoveAt(0);
            }
            */

            var jsonData = MiniJSON.Json.Deserialize(e.Data) as Dictionary<string,object>;
            string message = (string)jsonData["message"];
            if(message == "returnform")
            {
                //get Map Data
            }
            else if(message == "requestcreateform")
            {
                //createMap
            }
            else if(message == "returnscore")
            {
                // rannkinnguitiran
            }
            else if(message == "sendposition")
            {
                //anotherUserPosition
                Debug.Log("a");
            }
            else if(message == "setuserid")
            {
                SetUserID((string)jsonData["userID"]);
            }
            Debug.Log(message);
        };
        ws.OnError += (sender, e) =>
        {
            Debug.Log("aa");
        };
        ws.OnClose += (sender, e) =>
        {
            Debug.Log("Closing...");

        };
        ws.Connect();
        Debug.Log("Connect to " + ws.Url);
    }
开发者ID:ryuusinnca,项目名称:unity_socketIO,代码行数:53,代码来源:WebSocketClient.cs

示例13: Start

    // https://github.com/sta/websocket-sharp
    void Start()
    {
        socket = new WebSocket("ws://literature.uncontext.com:80");

        socket.OnError += (sender, e) => {
            Debug.Log ("socket Error: " + e.Message.ToString());
        };
        socket.OnMessage += (sender, e) => {
            Debug.Log ("socket message: " + e.Data);
        };

        socket.Connect();
    }
开发者ID:dattasaurabh82,项目名称:uncontext,代码行数:14,代码来源:CMain.cs

示例14: Reconnect

    public void Reconnect(string WebSocketServerAddress)
    {
        ws.Close();
        ws.OnMessage -= Ws_OnMessage;
        ws.OnOpen -= Ws_OnOpen;
        ws.OnClose -= Ws_OnClose;
        ws.OnError -= Ws_OnError;

        ws = new WebSocket(WebSocketServerAddress);
        ws.OnMessage += Ws_OnMessage;
        ws.OnOpen += Ws_OnOpen;
        ws.OnClose += Ws_OnClose;
        ws.OnError += Ws_OnError;
        ws.Connect();
    }
开发者ID:BahuMan,项目名称:MultiPong,代码行数:15,代码来源:PongWebSockets.cs

示例15: ListenToMtgox

        private static void ListenToMtgox()
        {
            var ws = new WebSocket("ws://" + Dns.GetHostAddresses("websocket.mtgox.com").First().ToString() + ":80/mtgox", "*");
            var observableWs = new ObservableWebsocket(ws);

            if (!ws.Connect())
            {
                Console.WriteLine("Not connected");
                Console.ReadLine();
            }
            else
            {
                Console.Clear();
                Connected(observableWs);
                ws.Close();
            }
        }
开发者ID:martindevans,项目名称:Bitcoin-Tradebot,代码行数:17,代码来源:Program.cs


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