unity3dsocket和javasocket通信byfeng侠

unity3dsocket和javasocket通信byfeng侠

ID:8963919

大小:109.50 KB

页数:24页

时间:2018-04-13

unity3dsocket和javasocket通信byfeng侠_第1页
unity3dsocket和javasocket通信byfeng侠_第2页
unity3dsocket和javasocket通信byfeng侠_第3页
unity3dsocket和javasocket通信byfeng侠_第4页
unity3dsocket和javasocket通信byfeng侠_第5页
资源描述:

《unity3dsocket和javasocket通信byfeng侠》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、Unity3D客户端:namespaceLSocket.Net { /****@authorfeng侠,qq:313785443*@date2010-12-23**///描述:封装c#socket数据传输协议 usingUnityEngine; usingSystem; usingSystem.Net.Sockets; usingSystem.Net; usingSystem.Collections; usingSystem.Text; usingLSocket.Type; usingLSocket.cmd; publicclassUnitySocket { publ

2、icstaticSocketmSocket=null; publicUnitySocket() { } publicstaticvoidSocketConnection(stringLocalIP,intLocalPort) { mSocket=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); try { IPAddressip=IPAddress.Parse(LocalIP); IPEndPointipe=newIPEndPoint(ip,LocalPort);

3、 mSocket.Connect(ipe); Send("");//thesecondconnect.ifit'snotequalspolicyhead,itwillcomeinthemainconnect! Send(CommandID.LOGIN); Send("feng"); strings=ReceiveString(100);//从服务器端接受返回信息 MonoBehaviour.print(s.Length); MonoBehaviour.print(s); } catch(Exceptione) { //E

4、rrLog.RecordErr(e,ModuleName,"AsySocket",""); } } publicstaticvoidSend(shortdata) { byte[]longth=TypeConvert.getBytes(data,false); mSocket.Send(longth); } publicstaticvoidSend(longdata) { byte[]longth=TypeConvert.getBytes(data,false); mSocket.Send(longth); } publicstaticvoidSend(in

5、tdata) { byte[]longth=TypeConvert.getBytes(data,false); mSocket.Send(longth); } publicstaticvoidSend(stringdata) { byte[]longth=Encoding.UTF8.GetBytes(data); mSocket.Send(longth); } publicstaticshortReceiveShort() { byte[]recvBytes=newbyte[2]; mSocket.Receive(recvBytes,2,0);//从服务器端接

6、受返回信息 shortdata=TypeConvert.getShort(recvBytes,true); returndata; } publicstaticintReceiveInt() { byte[]recvBytes=newbyte[4]; mSocket.Receive(recvBytes,4,0);//从服务器端接受返回信息 intdata=TypeConvert.getInt(recvBytes,true); returndata; } publicstaticlongReceiveLong() { byte[]recvBytes=newbyte[

7、8]; mSocket.Receive(recvBytes,8,0);//从服务器端接受返回信息 longdata=TypeConvert.getLong(recvBytes,true); returndata; } publicstaticstringReceiveString(intlength) { byte[]recvBytes=newbyte[length]; mSocket.Receive(recvBytes,length,0);//从服务器端接受返回信息 stringdata=Encoding.UTF8.GetString(recvB

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。