Unity3D 中的 Socket 通信
Posted on 2013 年 06 月 24 日 by U3d / Unity3D 脚本/插件/被围观 39 次
第一部分简单示例:连接服务器 Ip 端口,发送请求,接收数据同理。
public static void SocketConnect(string serverIP, int serverPort)
clientSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(serverIP),
serverPort);
clientSocket.Connect(ipe);
Debug.Log(" Connect Success IP: " + serverIP + " Port : "
+ serverPort.ToString());
Debug.LogError(e.ToString());
} //Unity3D
教程手册:
www.unitymanual.com
public static void Send(byte[] bytes)
if (clientSocket == null)
if (!clientSocket.Connected)
if (clientSocket.Poll(0, SelectMode.SelectWrite))
clientSocket.Send(bytes);
Debug.LogError(e.ToString());
第二部分请求数据示例:
public void _MSG_ACCOUNT(string name, string pwd)
ACCOUNT account = new ACCOUNT();
datas = new byte[account.length];
评论0
最新资源