利用socket简单的实现,客户端和服务器之间的通信。
客户端:
using UnityEngine;
using System.Collections;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
public class client : MonoBehaviour {
void Start () {
ConncetServer();
}
void ConncetServer()
{
IPAddress ipAdr = IPAddress.Parse("10.130.28.9");
IPEndPoint ipEp=new IPEndPoint(ipAdr,7000);
Socket clientScoket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
clientScoket.Connect(ipEp);
string output="client requeset";
byte[] concent=Encoding.UTF8.GetBytes(output);
clientScoket.Send(concent);