using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
using System.Text; using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using UnityEngine.UI;
using UnityEngine.Networking; public class ss : MonoBehaviour {
public TcpClient client;
public BinaryReader breader;
public BinaryWriter bwriter;
public NetworkStream netstream;
string abc = "";
string abc0 = "";
Text text;
public bodyController CF;
public float m_speed = 5f;
private static Socket clientSocket;
private static byte[] result = new byte[1024];
// Use this for initialization
void Start () {
CF = GameObject.Find("RimaVirtualBody/rima").GetComponent<bodyController>();
client = new TcpClient("172.20.20.241", 8140);
// client = new TcpClient("127.0.0.1", 8139);
// netstream = client.GetStream();
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//IPAddress mIp = IPAddress.Parse("172.20.20.241");
//IPEndPoint ip_end_point = new IPEndPoint(mIp, 8140);
IPAddress mIp = IPAddress.Parse("127.0.0.1");
IPEndPoint ip_end_point = new IPEndPoint(mIp, 8140); clientSocket.Connect(ip_end_point); //breader = new BinaryReader(netstream);
// bwriter = new BinaryWriter(netstream); Thread threadReceive = new Thread(new ThreadStart(ReceiveData));
threadReceive.IsBackground = false;
threadReceive.Start(); //text = GameObject.Find("Canvas/Text").GetComponent<Text>();
}
private void ReceiveData()
{ int length = clientSocket.Receive(result);
//string receiveSting = null;
abc = Encoding.UTF8.GetString(result, 0, length); Debug.Log(abc); } // Update is called once per frame
void Update () {
if(abc!=abc0)
{
if (abc == "聆听") CF.hear();
if (abc == "跳舞") CF.dance();
if (abc == "谈话") CF.talk();
if(abc=="立正") CF.idle(); abc0 = abc;
}
else
{ }
}
}

总是只接受一个字符串,或者把对方发来的接成yige

前者原因是while(true)漏了,后者是因为没关闭clientSocket.Receive,可以clientSocket.close();

        while (true)
{
int length = clientSocket.Receive(result);
//string receiveSting = null;
abc = Encoding.UTF8.GetString(result, 0, length);
Debug.Log(abc);
}

前者改动后可以省略后者的改动。

最新文章

  1. Google Android 6.0 权限完全解析
  2. web服务器页面错误代码集
  3. Webloigic监控
  4. Java 数据类型之间的转换 拆分字符串 Date/Calendar的转换
  5. Delphi 保存写字板程序, 并进行打印
  6. iOS App中数据加载的6种方式
  7. 解决Lost connection to MySQL server at &#39;reading initial communication packet&#39;, 的方法
  8. 使用 Socket.IO 开发聊天室
  9. 模块使用:time、datetime、calendar、sys、os、os.path、normcase和normapath、random、json、pickle
  10. Sql学习笔记(二)—— 条件查询
  11. Oracle debug
  12. LeetCode 145 二叉树的后序遍历(非递归)
  13. java高级进阶
  14. day022 python (re模块和 模块)
  15. Linux 下的编译安装说明
  16. Xianfeng轻量级Java中间件平台:功能管理
  17. 【python】列表&amp;&amp;元组&amp;&amp;字典
  18. python的函数介绍 位置参数 关键字参数 默认参数 参数组 *args **kwargs
  19. Fiddler手机https抓包
  20. jmeter -分布式性能测试部署

热门文章

  1. centos下修改hosts文件以及生效命令
  2. 『与善仁』Appium基础 — 29、获取toast信息
  3. 【LeetCode】657. Judge Route Circle 解题报告
  4. 【LeetCode】398. Random Pick Index 解题报告(Python & C++)
  5. CF 593B Anton and Lines(水题)
  6. 【剑指Offer】滑动窗口的最大值 解题报告(Python)
  7. Parenthesis
  8. Towards Evaluating the Robustness of Neural Networks
  9. 如何在HTML中添加表格标题?(HTML中table添加标题的2种方法)
  10. Java程序设计基础笔记 • 【第7章 Java中的类和对象】