纳金网

标题: UNITY3D SOCKET通信 [打印本页]

作者: 她。    时间: 2012-11-7 08:53
标题: UNITY3D SOCKET通信
using UnityEngine;
using System.Collections;
using System.ComponentModel;
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
//using System.Threading;public class MyNet : MonoBehaviour {//public string SendM = “发送信息”;
//public string server = “主机IP”;
string SendM = “发送信息”;
string server = “主机IP”;private Socket socket; // Use this for initialization
void Start () {}// Update is called once per frame
void Update () {}void OnGUI() {
SendM = GUI.TextField(new Rect(0,0,120,20),SendM);
server = GUI.TextField(new Rect(0,20,120,20),server);if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2, 120, 60), “start”))
{
socket = new Socket (AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint tempRemoteIP = new IPEndPoint (IPAddress.Parse(server),端口号);
EndPoint epTemp = (EndPoint)tempRemoteIP;
socket.Connect(epTemp);Byte[] bytesSent = Encoding.ASCII.GetBytes(SendM);
socket.Send(bytesSent,bytesSent.Length,0);socket.Close();
}
}
}
如果对你们有帮助的话顶顶吧
作者: may    时间: 2012-11-30 04:08
支持一下楼主




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5