unity客户端
来源:互联网 发布:布道者软件 编辑:程序博客网 时间:2024/05/16 13:03
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;public class unityClient : MonoBehaviour { private Socket socket; public InputField input; private byte[] date = new byte[1024]; private Thread t; private string message; public Text text;// Use this for initializationvoid Start () { ConnectToServer();} void Update() { if (message != null&&message != "") { text.text += message+"\n"; message = ""; } } void ConnectToServer() { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ip = IPAddress.Parse("192.168.2.100"); IPEndPoint point = new IPEndPoint(ip, 7788); socket.Connect(point); t = new Thread(ReciveReceiveMessage); t.Start(); } void ReciveReceiveMessage() { while (true) { if (socket.Connected == false) break; int count = socket.Receive(date); message = Encoding.UTF8.GetString(date, 0, count); } } void SendMessage(string message) { byte[] date = Encoding.UTF8.GetBytes(message); socket.Send(date); } public void OnSendBtn() { string str = input.text; SendMessage(str); input.text = ""; } void OnDestroy() { socket.Shutdown(SocketShutdown.Both); socket.Close(); }}
0 0
- unity客户端
- Unity 网游客户端Dome
- unity 客户端 服务端 连接
- Unity客户端笔试题
- Unity 客户端知识体系
- Unity客户端架构-Util
- Unity客户端架构-UIContainer
- Unity客户端架构-io
- Unity客户端架构-Resource
- Unity客户端架构-PanelManager
- Unity客户端架构-DialogManager
- Unity客户端架构-BaseDialog
- Unity客户端架构-DialogInfo
- Unity客户端架构-DialogType
- Unity客户端架构-GlobalGenerator
- Unity客户端框架
- Unity客户端设计系列
- Unity客户端断点续传
- unity聊天室服务器端
- 【Hadoop2.7.0、Zookeeper3.4.6、JDK1.7】搭建完全分布式的hadoop,HA部署安装,自动备援
- c++
- UVa 12096 The SetStack Computer 【STL】【stack】
- rt2860v2源码分析三
- unity客户端
- ASP.NET MVC中使用Log4Net
- Android AsyncTask使用详解
- 算法分析课每周练习 Max Points on a Line
- [LeetCode] 91. Decode Ways
- ant使用
- nginx启用brotli压缩算法
- 文章标题
- 关于并行计算的一些名词