12-游戏设计/五子棋/五子棋/UDPSocket.cs
(开头部分) 6KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Windows.Forms;//在引用中添加windows窗体
using System.Threading;
namespace 五子棋
{
public partial class UDPSocket : Component
{
#region 全局变量
private IPEndPoint ServerEndPoint = null; //定义网络端点
private UdpClient UDP_Server = new UdpClient(); //创建网络服务,也就是UDP的Socket
private System.Threading.Thread thdUdp; //创建一个线程
private string localHost = "127.0.0.1";
#endregion
#region 定义组件的事件
public delegate void DataArrivalEventHandler(byte[] Data, IPAddress Ip, int Port); //定义了一个托管方法
public event DataArrivalEventHandler DataArrival; //通过托管理在控件中定义一个事件
#endregion
#region 定义组件的属性
[Browsable(true), Category("Local"), Description("本地IP地址")] //在“属性”窗口中显示localHost属性
public string LocalHost
{
get { return localHost; }
set { localHost = value; }
}
private int localPort = 11000;
[Browsable(true), Category("Local"), Description("本地端口号")] //在“属性”窗口中显示localPort属性
public int LocalPort
{
get { return localPort; }
set { localPort = value; }
}
private bool active = false;
[Browsable(true), Category("Local"), Description("激活监听")] //在“属性”窗口中显示active属性
public bool Active
{
get { return active; }
set //该属性读取值
{
active = value;
if (active) //当值为True时
{
OpenSocket(); //打开监听
}
else
{
CloseSocket(); //关闭监听
}
后面还有 119 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读 AI
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
