ServerSocket->Close() 与 ServerSocket->Socket->Close() 有什么不同。

s98231106 2003-03-10 02:29:57
by the way :

ServerSocket->Open() 与 ServerSocket->Socket->Open() 有什么不同。
...全文
217 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanlianjun 2003-03-14
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1458/1458872.xml?temp=.4466822
常宁 2003-03-13
  • 打赏
  • 举报
回复
to yuanlianjun(头晕眼花)
正确地用法应该是调用ServerSocket->Active=false;
从源码中可以看到,他会调用ServerSocket->Close(),而这个函数会在适当的时候调用ServerSocket->socket->Close();在这之前,他还会关闭所有的子连接,而不需要一个一个关闭
现在总结一下:
第一,推荐用ServerSocket->Active=false/true关闭或者启动TCP Server
第二,ServerSocket->Socket->Close();的用处是关闭Listen端口并释放相应资源
第三,ServerSocket->close()释放所有的socket资源,包括Listen以及子连接socket资源
第三,不要多次释放socket,经管这样不会产生错误,也就是说不要用yuanlianjun(头晕眼花)的方法。
第四,ServerSocket是典型的异步事件驱动的windows socket模型,而且封装完好,如果不能清楚理解这个类的精妙,不要枉自猜疑。



SharpKing515 2003-03-12
  • 打赏
  • 举报
回复
GZ!
yuanlianjun 2003-03-11
  • 打赏
  • 举报
回复
最重要的一点:关闭套接字时一定要用ServerSocket->Socket->Close() ,否则系统不会释放套接字被创建时分配的资源。如果使用 ServerSocket->Close() 不断重新生成,系统缓冲会明显减少最后不足出错。
耙子 2003-03-10
  • 打赏
  • 举报
回复
ServerSocket->Open() 最终会调用 ServerSocket->Socket->Open()
我不懂电脑 2003-03-10
  • 打赏
  • 举报
回复
Opens the socket connection.

ServerSocket->Open()
void __fastcall Open(void);

Description

Call Open to initiate the socket connection. Open sets the Active property to true.

For client sockets, Open locates and connects to a server. For server sockets, Open opens the socket connection in a listening mode, but does not complete the connection to a client socket.

ServerSocket->Socket->Open()
Opens a connection to a remote socket.

void __fastcall Open(const AnsiString Name, const AnsiString Address,
const AnsiString Service, Word Port, bool Block);

Description

Client socket components call Open to open a connection to a server socket.

Open creates the Windows socket that will connect to the server socket, and generates an OnSocketEvent of type seLookup. After the OnSocketEvent, Open binds the Windows Internet socket address derived from the parameters to the socket, locating the server socket. Open then generates an OnSocketEvent of type seConnecting. When the server socket accepts the connection, Open completes the connection to the server socket. Then it generates an OnSocketEvent of type seConnect. After the OnSocketEvent, the Connected property is set to true.

The Name, Address, Service, and Port parameters are taken from the Host, Address, Service and Port properties of the client socket component.

Block indicates whether the socket can look up the information it needs to establish a connection asynchronously. When Block is true, the socket blocks execution for each lookup instead of retrieving information about the connection using asynchronous notifications.

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧