用socket进行连接的时候出现错误:通常每个套接字地址 协议 网络地址 端口 只允许使用一次。
运行环境win2000server,请高手解答,比较及,分还可以加。
谢谢
程序代码如下:
- C# code
static void Main(string[] args)
{
AppMain app = new AppMain();
// connStr = app.GetConnStr();
// Welcome and Start listening
app.log.WriteLog("*** ESP Server Started " + DateTime.Now.ToString( "G" ) + "***" , EventLogType.Information);
int nPortListen = app.GetPort();//7893;
app.GetBufferSize();
Socket listener = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
listener.Bind( new IPEndPoint( IPAddress.Any ,nPortListen ) );
listener.Listen( 500 );
app.log.WriteLog("Listening on : " + nPortListen , EventLogType.Information);
// app.StartMt();
listener.BeginAccept( new AsyncCallback( app.OnConnectRequest ), listener );
Console.WriteLine ("Press Enter to exit" );
Console.ReadLine();
app.log.WriteLog("Server is Closed",EventLogType.Information);
app.mas.Close();//关闭mas
// Clean up before we go home
try
{
app.workflag = false;
listener.Close();
app.rotation1.Abort();
int tol = app.m_aryClients.Count;
int i = 0;
while(i < tol )
{
SocketChatClient client = (SocketChatClient)app.m_aryClients[i];
client.Sock.Shutdown(SocketShutdown.Send);
client.SendIsVal = false;
i++;
app.m_aryClients.Remove(client);
}
}
catch(Exception e)
{
app.log.WriteLog(e,"关闭异常");
}
// Console.ReadLine();
}
------解决方案--------------------------------------------------------
对
------解决方案--------------------------------------------------------
鼎
------解决方案--------------------------------------------------------
我在写一个即时通的时候也遇到了,不过还不会解决!只能搁置。只能帮顶了!
------解决方案--------------------------------------------------------
应该是端口冲突..你试着换别的端口试试.tcp协议一个套接字只能对应一个端口的..