5

I'm just starting to get familiar with Embarcadero RAD Studio 2010 after living a life of Eclipse, Emacs, Visual Studio and notepad :)

I'm jumping into quite a large C++ application (500.000 - 1.000.000 lines) that I found made extensive use of TClientSocket and TServerSocket. The IDE first complanied about that TClientSocket was not found but could still compile and I scratched my head. Then I found out that it's not installed by default anymore and is marked as deprecated since way back.

I have tried to read about the subject but haven't found much information. My questions are

  • Why are TClientSocket and TServerSocket deprecated?
  • How do they differ in the way they function from WinSock and BSD sockets?
  • What would be best to use instead and is there a quick replacement that would not involve going through the entire application and changing everywhere TClientSocket and TServerSocket are being used? I would guess that it would mostly be the inner workings that have changed or?
4

2 回答 2

3

已弃用,因为不再受支持。它们是 Winsock 套接字的封装,因此整体内部机制是相同的 - “创建侦听器、侦听、接受,创建客户端处理程序线程,将 ServerClientSocket 传递给它,客户端线程读取和写入流”。

您也许可以尝试只导入组件 - 如果您有一个庞大的遗留应用程序需要支持,那么如果它有效,那么这肯定是要走的路。

然后还有另一种方式 :(( 使用 Indy 或 Synapse 组件构建具有相同成员的“TClientSocket”和 TServerSocket 类,以便旧版应用程序无需大量更改即可工作。

于 2011-05-27T08:21:03.080 回答
0

它们已被弃用,取而代之的是 Indy 套接字。

但是,Indy 套接字是仅阻塞的。如果您的程序使用阻塞套接字,那么这很好,但是如果您使用非阻塞套接字,那么据我所知,您只有两个选择:

  • 使用线程加上阻塞 Indy 套接字
  • 使用 TClientSocket 和 TServerSocket

有一些组件可以在阻塞TTcpServerTTcpClient非阻塞之间切换。但是,如果您在非阻塞模式下操作它们,它们就不起作用(基本操作因 WSAEWOULDBLOCK 失败)并且没有解决方法。

dclsocketsNNN.bpl其他阅读本文但可能不知道的人请注意:即使在最新版本中(如我所写),您仍然可以通过添加到设计时包列表中将它们导入 IDE 。它们在那里,只是默认情况下不活动。

就我个人而言,我仍然在生产中以非阻塞模式使用 TClientSocket,它工作得很好(在修复了一些错误之后,这可能要归功于提供了完整的源代码!)

于 2014-05-15T12:16:36.667 回答