⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.cs

📁 .net2003 C# 基于pda的winsock通讯
💻 CS
字号:
using System;
using System.Net;
using System.Net.Sockets;

namespace SmartDeviceApplication5
{
	public class Server:SocketBase
	{
		

		private TcpListener _listener;
		public Server()
		{
			this._connections = new ConnectionCollection();
		}
		protected System.Threading.Thread _listenConnection;

		public void StartServer(int port) {
			_listener = new TcpListener(IPAddress.Any, port);
			_listener.Start();

			_listenConnection = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
			_listenConnection.Start();

			this.StartListenAndSend();
		}
		public void StopServer() {
			this.EndListenAndSend();
			
		}
		private void Start() {
			try {
				while(true) {
					if(_listener.Pending()) {
						TcpClient client = _listener.AcceptTcpClient();
						NetworkStream stream = client.GetStream();
						Connection connection = new Connection(stream);
						this._connections.Add(connection);
						this.OnConnected(this,new ConnectionEventArgs(connection,new Exception("连接成功")));
					}
					System.Threading.Thread.Sleep(200);
				}	
			}
			catch {
				 }
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -