unity与winform 使用socket通信
下载Demo地址:unity与winformsocket通信
一. 在unity中
- unity作为服务端,接收winform发来的消息,需要先建立服务端,等待客户端连接
private void SocketConnet()
{
//if (_ClientSocket != null)
// _ClientSocket.Close();
//控制台输出侦听状态;
Debug.Log("Waiting for a client");
_ClientSocket = _ServerSocket.Accept();
//获取客户端的IP和端口;
IPEndPoint ipEndClient = _ClientSocket.RemoteEndPoint as IPEndPoint;
//输出客户端的IP和端口
Debug.Log("Connect with" + ipEndClient.Address.ToString() + ":" + ipEndClient.Port.ToString())