unity3d C# soket客户端接受失败

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);
        }
前者改动后可以省略后者的改动。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Xfrog 3DS MAX PlugIn (07/04/2002) ======================================== Installation ------------------------------------------------- Copy the file xfrog.dlo into your plugins directory (e.g. c:\3dsmax42\plugins). Compatibility ------------------------------------------------- The PlugIn is compiled for discreet 3DS MAX 4.2+. It will not work with prior versions of 3DS MAX. Usage ------------------------------------------------- 1. Choose 'Import' from the 'File' Menu 2. Select 'Xfrog (*.XFR)' as File Import Filter and choose the Xfrog Model to import. Click OK. 4. The model and material should show up now. Feel free to modify the materials, changes made to the mesh itself will be overridden when the object is reevaluated. Options Panel ------------------------------------------------- The Animation Length Group lets you choose between the Animation Length preset in the file, a custom length to be specified, the length being scaled to fit the current animation length or to be ignored. For static models you should always change this setting to Ignore, this will prevent the model from being recreated when you move the frame slider. An existing Animation can be played back as a loop, swinging back and forth and only once. For faster redraws in viewport or for preview rendering you may also want to change the model quality in viewport and for rendering with the sliders at the bottom of the panel. If you need to access the geometry on a per component level you can do that by converting the object to an Editable Mesh, and choose Select By Material ID in Polygon Selection Mode. This will disable animation as the reference to the original Xfrog file is removed.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值