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


C# WebSocket.SendString方法代码示例

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


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

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

示例2: Start

	// Use this for initialization
	IEnumerator Start () {
        WebSocket w = new WebSocket(new Uri("ws://192.168.1.206:8888/ws"));
		yield return StartCoroutine(w.Connect());
		w.SendString("UnityTest");
		int i=0;
		while (true)
		{
			string reply = w.RecvString();
			if (reply != null)
			{
				Debug.Log ("Received: "+reply);
                w.SendString("UnityTest " + i++);
			}
			if (w.Error != null)
			{
				Debug.LogError ("Error: "+w.Error);
				break;
			}
			yield return 0;
		}
		w.Close();
	}
开发者ID:nermakov777,项目名称:Unity_Tests,代码行数:23,代码来源:EchoTest.cs

示例3: Start

 // Use this for initialization
 IEnumerator Start()
 {
     WebSocket w = new WebSocket(new Uri("ws://127.0.0.1:3000"));
     yield return StartCoroutine(w.Connect());
     w.SendString("Hi there");
     int i = 0;
     while(true)
     {
         string reply = w.RecvString();
         if(reply != null)
         {
             Debug.Log("Received: " + reply);
             w.SendString("Hi there" + i++);
         }
         if(w.Error != null)
         {
             Debug.LogError("Error: " + w.Error);
             break;
         }
         yield return 0;
     }
     w.Close();
 }
开发者ID:coil398,项目名称:bomberman,代码行数:24,代码来源:ConnectionToNode.cs

示例4: Connecting

        IEnumerator Connecting()
        {
            var env = ConstantEnviroment.Instance;
            string uri = env.Network.GetAddress(env.Scene.GetPort(SceneManager.GetActiveScene().name));
            Debug.Log("[Connecting] IP=" + uri + " Group=" + MyPlayerController.Instance.Group);
            var socket = new WebSocket(new Uri(uri));
            yield return StartCoroutine(socket.Connect());

            JsonHash hash = new SyncStatus() { Group = MyPlayerController.Instance.Group, Status = NetworkStatus.Join }.ToHash();
            socket.SendString(Json.Serialize(new JsonList() { hash }));

            while (true)
            {
                yield return null;
                var recv = socket.RecvString();
                Retrieve(recv);
                while(_SynchronizedQueue.Count > 0)
                {
                    Synchronized s = _SynchronizedQueue.Dequeue();
                    SyncStatus status = s as SyncStatus;
                    if (status == null) continue;

                    if (status.Status == NetworkStatus.Accept)
                    {
                        // サーバーと接続できた時
                        Synchronized.MyGroup = status.Group;	// 自分のGroupを登録
                        Synchronized.MyId = status.ShortId;	// 自分のIDを登録
                        MyPlayerController.Instance.SetID(status.Group, status.ShortId);
                        _StartTime = status.Time;	// 始まった時間
                        _WebSocket = socket;	// ソケット登録
                        Debug.Log("[Connected] Group=" + status.Group + " ID=" + Synchronized.MyId + " Time=" + _StartTime);
                        yield break;
                    }
                }
            }
        }
开发者ID:hidetobara,项目名称:Painter,代码行数:36,代码来源:NetworkManager.cs

示例5: StartWebSocket_CR

    // Use this for initialization
    IEnumerator StartWebSocket_CR()
    {
        WebSocket w = new WebSocket(new Uri("ws://128.2.236.66:3000"));
        yield return StartCoroutine(w.Connect());

		w.SendString("Ctrl Connected");
        while (true)
        {
            string res = w.RecvString();
			if (res != null)
            {
#if UNITY_EDITOR
                Debug.Log("Received: " + res);
#endif
                //w.SendString("Hi there" + i++);
                char[] delimiterChars = { ' ' ,'\t' };
				string[] parseStr = res.Split(delimiterChars);

				switch(parseStr[0]){
					case "m+":{
					_crowdSim.globalAttentionMean = SetValueFromString(_crowdSim.globalAttentionMean, true, parseStr);
						break;
					}
					case "m-":{
					_crowdSim.globalAttentionMean = SetValueFromString(_crowdSim.globalAttentionMean, false, parseStr);
						break;
					}
					case "d+":{
					_crowdSim.globalAttentionStDev = SetValueFromString(_crowdSim.globalAttentionStDev, true, parseStr);
						break;
					}
					case "d-":{
						_crowdSim.globalAttentionStDev = SetValueFromString(_crowdSim.globalAttentionStDev, false, parseStr);
						break;
					}
					case "u+":{
						_crowdSim.seatPosAttentionUpper = SetValueFromString(_crowdSim.seatPosAttentionUpper, true, parseStr);
						break;
					}
					case "u-":{
						_crowdSim.seatPosAttentionUpper = SetValueFromString(_crowdSim.seatPosAttentionUpper, false, parseStr);
						break;
					}
					case "l+":{
						_crowdSim.seatPosAttentionLower = SetValueFromString(_crowdSim.seatPosAttentionLower, true, parseStr);
						break;
					}
					case "l-":{
						_crowdSim.seatPosAttentionLower = SetValueFromString(_crowdSim.seatPosAttentionLower, false, parseStr);
						break;
					}

				}
			
				w.SendString("|Unity> currStat: m=" + _crowdSim.globalAttentionMean + ", dev=" + _crowdSim.globalAttentionStDev 
				             + ", A_up=" + _crowdSim.seatPosAttentionUpper + ", A_Low=" +  _crowdSim.seatPosAttentionLower + "." );

				
				//w.SendString("|Unity> blar blar" + res);

            }
            if (w.Error != null)
            {
#if UNITY_EDITOR
                Debug.Log("Error: " + w.Error);
#endif
                break;
            }
            yield return 0;
        }
        w.Close();
    }
开发者ID:MangoSister,项目名称:VR_Rehearsal,代码行数:73,代码来源:FakeCrowdController.cs

示例6: StartCommunicator

    /// Use this for initialization
    IEnumerator StartCommunicator()
    {
        WebSocket w = new WebSocket(new Uri("ws://192.168.33.138:8080"));
        if(!testLocally) {
            yield return StartCoroutine(w.Connect());
            w.SendString("Hi there, I'm the communicator");
        }
        int i=0;
        while (true)
        {
            sendingIntervalCountdown -= Time.deltaTime;
            if(sendingIntervalCountdown < 0) {
                sendingIntervalCountdown = sendingInterval;
                String toSend = "{\"x\":"+ball.position.x+",\"y\":"+ball.position.z+",\"z\":"+ball.position.y+"}";
                Debug.Log(toSend);
                if(!testLocally) {
                    w.SendString (toSend);
                }
            }
            string reply = null;
            if(!testLocally) {
                reply = w.RecvString();
            } else {
                reply = localTestCommand;
                localTestCommand = null;
            }
            if (reply != null)
            {
                Debug.Log ("Received: "+reply);
                Vector3 force = Vector3.zero;
                /*if(reply != null && reply.Length == ) {
                    if(reply[0] == '#') {

                    }
                }*/
                switch(reply) {
                case "jump":
                    force = new Vector3(0, 300, 0);
                    break;
                case "left":
                    force = new Vector3(500, 0, 0);
                    break;
                case "right":
                    force = new Vector3(-500, 0, 0);
                    break;
                case "forward":
                    force = new Vector3(0, 0, 500);
                    break;
                case "backward":
                    force = new Vector3(0, 0, -500);
                    break;
                case "color":
                    force = new Vector3(0, 0, -500);
                    break;
                }
                //Debug.Log (force);
                ball.GetComponent<Rigidbody>().AddForce(force);
                //w.SendString("Hi there"+i++);
            }
            if (!testLocally && w.error != null)
            {
                Debug.LogError ("Error: "+w.error);
                break;
            }
            yield return 0;
        }
        w.Close();
    }
开发者ID:BahuMan,项目名称:Game-Of-Everything,代码行数:69,代码来源:Communicator.cs

示例7: StartGenerateData

 // Call this second client to actually send random commands.
 IEnumerator StartGenerateData()
 {
     WebSocket w = new WebSocket(new Uri("ws://192.168.33.138:8080"));
     if(!testLocally) {
         yield return StartCoroutine(w.Connect());
         w.SendString("Hi there, I'm the random generator");
     }
     int i=0;
     while (true)
     {
         String[] elements = {"jump", "left", "right", "forward", "backward"};
         String randomElem = elements[UnityEngine.Random.Range(0,elements.Length)];
         Debug.Log(randomElem);
         if(!testLocally) {
             w.SendString(randomElem);
         } else {
             localTestCommand = randomElem;
         }
         if (!testLocally && w.error != null)
         {
             Debug.LogError ("Error: "+w.error);
             break;
         }
         yield return new WaitForSeconds(1f);
     }
     w.Close();
 }
开发者ID:BahuMan,项目名称:Game-Of-Everything,代码行数:28,代码来源:Communicator.cs


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