Unity Socket UDP
来源:互联网 发布:linux怎么设置搜狗 编辑:程序博客网 时间:2024/05/16 08:55
- using System.Collections;
- using System.Collections.Generic;
- using System.Net.Sockets;
- using System.Net;
- using System.Threading;
- using System.Text;
- public class SocketUDPServer
- {
- private string ip = "127.0.0.1";
- private int port = 5690;
- private Socket socket;
- private static SocketUDPServer socketServer;
- public List<string> listMessage = new List<string>();
- public static SocketUDPServer getInstance()
- {
- if (socketServer == null)
- {
- socketServer = new SocketUDPServer();
- socketServer.Init();
- }
- return socketServer;
- }
- private void Init()
- {
- IPAddress ipAddress = IPAddress.Parse(ip);
- IPEndPoint IPE = new IPEndPoint(ipAddress,port);
- //Udp搭配SocketType.Dgram Tcp搭配SocketType.Stream
- socket=new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
- socket.Bind(IPE);
- Thread threadReceive = new Thread(new ThreadStart(ReceiveMessage));
- threadReceive.Start();
- }
- private void ReceiveMessage()
- {
- while (true)
- {
- byte[] buff = new byte[1024];
- int iBytes = socket.Receive(buff, SocketFlags.None);
- if (iBytes <= 0)
- break;
- string strGetMessage = Encoding.ASCII.GetString(buff, 0, iBytes);
- listMessage.Add(strGetMessage);
- }
- }
- public void Close()
- {
- if(socket!=null)
- socket.Close();
- }
- }
阅读全文
0 0
- Unity Socket UDP
- Unity Socket UDP
- unity开发:UDP socket网络连接
- socket/TCP/UDP基础及Unity聊天室的实现
- socket udp
- socket UDP
- socket udp
- UDP Socket
- SOCKET UDP
- UDP Socket
- udp socket
- socket udp
- udp socket
- udp socket
- Socket-UDP
- UDP socket
- socket(UDP)
- socket udp
- 点到平面的距离公式
- AngularJs全选反选的代码
- 在UTF-8中,一个汉字为什么需要三个字节?
- 选择算法
- 为什么选择rabbitmq
- Unity Socket UDP
- 使用jersey框架上传图片到图片服务器
- liunx网络编程(1)
- 获取list集合指定变量的值的集合
- java 生成二维码
- 单域名下多子域名同时认证HTTPS
- 图的割点、桥和双连通分支的基本概念
- 1054. 求平均值 (20) PAT乙级真题
- Linux php安装fileinfo扩展