c# socket 连接问题

来源:百度知道 编辑:UC知道 时间:2024/06/24 22:56:09
问题很简单
晕,还没弄好就提交了
这样 , socket 主机

Socket socket=new Socket(....,....,....);
try
{
socket.Blind(...);
socket.Listen( 问题在这里, 这个参数是做什么用的? 难道socket accept以后又重新回来再次接收啊?,如果这样,socket获得连接后我如何处理所得到的socket呢? );
socket.accept()
}
catch(Exception ex)
{
....
}

抱歉,小生c#菜鸟级任务, 很少用c#, 请各位大虾指教

1.简单服务器端
//using System.Data;
//using System.net.Sockets;
//using System.net;
//using System.Threading;
int port=%%2;
private Thread thThreadRead;
private TcpListener TcpListen;
private bool bListener=true;
private Socket stRead;
void Listen()
{
tlTcpListen=new TcpListener(port);
tlTcpListen.Start();
stRead=tlTcpListen.AccepSocket();
EndPoint tempRemoteEP=skSocket.RemoteEndPoint;
IPEndPoint tempRemoteIP=(IPEndPoint)tempRemoteEP;
IPHostEntry host=Dns.GetHostByAddress(tempRemoteIP.Address);
string sHostName=host.HostName;
while(bListener)
{
string sTime=DateTime.Now.ToShortTimeString();
Byte[] byRead=new Byte[1024];
int iRead=stRead.ReceiveFrom(byRead,ref tempRemoteEP);
Byte[] byText=new Byte[iRead];
Array.Copy(byRead,0,byText,0,iRead);
string %%5=System.Text.Encoding.Default.GetString(stream);
}
}
catch(Security.SecurityException)
{