(第三季)604-unity聊天室-创建unity客户端,开发建立连接的代码

来源:互联网 发布:软件图片 编辑:程序博客网 时间:2024/06/06 13:21




using UnityEngine;using System.Collections;using System.Net.Sockets;using System.Net;public class ChatManager : MonoBehaviour {    public string ipaddress = "192.168.51.102";    public int port = 7788;    private Socket clientSocket;// Use this for initializationvoid Start () {        ConnectToServer();    }// Update is called once per framevoid Update () {}    void ConnectToServer()    {        clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);        // 跟服务器端建立连接        clientSocket.Connect(new IPEndPoint(IPAddress.Parse(ipaddress), port));            }}








0 0
原创粉丝点击