C# Socket编程

来源:百度知道 编辑:UC知道 时间:2024/09/24 22:46:36
C# SOCKET能够用到WEBFORM吗.... 要怎么做?
像WINFORM一样 多线程 监听可以吗?

1.简单服务器端
/*
using System.Data;
using System.Net.Sockets;
using System.Net;
using System.Threading;
*/
private static int port = %%2;
private static Thread thThreadRead;
private static TcpListener TcpListen;
private static bool bListener = true;
private static Socket stRead;
private static void Listen()
{
try
{
TcpListen = new TcpListener(port);
TcpListen.Start();
stRead = TcpListen.AcceptSocket();
EndPoint tempRemoteEP = stRead.RemoteEndPoint;
IPEndPoint tempRemoteIP = (IPEndPoint)tempRemoteEP;
IPHostEntry host = Dns.GetHostByAddress(tempRemoteIP.Address);
string sHostName = host.HostName;
while (bListener)
{
stRead.Send(Encoding.ASCII.GetB