当前位置:文档之家› C#语言编程 服务器端与客户端对话 源程序代码

C#语言编程 服务器端与客户端对话 源程序代码


using System;

using System.Collections.Generic;

using System.Windows.Forms;

using https://www.doczj.com/doc/135476967.html,;

using https://www.doczj.com/doc/135476967.html,.Sockets;

using System.Threading;

namespace AsyncTcpServer

{

public partial class FormServer : Form

{

/// <summary>保存连接的所有用户</summary>

private List<User> userList = new List<User>();

/// <summary>使用的本机IP地址</summary>

IPAddress localAddress;

/// <summary>监听端口</summary>

private const int port = 51888;

private TcpListener myListener;

/// <summary>是否正常退出所有接收线程</summary> bool isExit = false;

public FormServer()

{

InitializeComponent();

listBoxStatus.HorizontalScrollbar = true;

IPAddress[] addrIP =

Dns.GetHostAddresses(Dns.GetHostName());

//localAddress = addrIP[0];

foreach (var ip in addrIP)

{

//判断是否为IPv4地址

if (ip.AddressFamily == AddressFamily.InterNetwork) {

localAddress = ip;

break;

}

}

buttonStop.Enabled = false;

}

/// <summary>【开始监听】按钮的Click事件</summary> private void buttonStart_Click(object sender, EventArgs e)


相关主题
文本预览
相关文档 最新文档