为什么不推荐使用 TClientSocket 和 TServerSocket?我应该使用什么来代替?
在经历了 Eclipse、Emacs、Visual Studio 和记事本的生活之后,我刚刚开始熟悉 Embarcadero RAD Studio 2010 :)
我正在跳入一个相当大的 C++ 应用程序(500.000 - 1.000.000 行),我发现它是由大量使用TClientSocket和TServerSocket。 IDE 首先抱怨没有找到 TClientSocket,但仍然可以编译,这让我摸不着头脑。然后我发现它不再默认安装,并且从很久以前就被标记为已弃用。
我尝试阅读有关该主题的内容,但没有找到太多信息。我的问题是
- 为什么 TClientSocket 和 TServerSocket 被弃用?
- 它们的功能与 WinSock 和 BSD 套接字有何不同?
- 最好使用什么来代替?是否有一种快速替代方案,不需要遍历整个应用程序并更改正在使用的所有 TClientSocket 和 TServerSocket?我猜想这主要是内部运作方式发生了变化,或者?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
已弃用,因为不再支持。它们是 Winsock 套接字的包装,因此整体内部机制是相同的 - “创建侦听器,侦听,接受,创建客户端处理程序线程,将 ServerClientSocket 传递给它,客户端线程读取和写入流”。
您也许可以尝试仅导入组件 - 如果您有大量的遗留应用程序需要支持,那么如果它有效的话,这肯定是可行的方法。
然后还有另一种方法:(( 使用 Indy 或 Synapse 组件构建具有相同成员的“TClientSocket”和“TServerSocket”类,以便遗留应用程序无需进行大量更改即可运行。
Deprecated because not supported any more. They are a wrap up of Winsock sockets, so the overall internal mechanism is the same - 'Create listener, listen, accept, create a client handler thread, passing it the ServerClientSocket, client thread reads and writes streams'.
You could maybe try just importing the components - if you have a massive legacy app to support, then this is surely the way to go if it works.
Then there's the other way :(( Use Indy or Synapse components to build 'TClientSocket' and TServerSocket' classes with identical members so that the legacy app will work without massive changes.
它们已被弃用,取而代之的是 Indy 套接字。
然而,Indy 套接字是仅限阻塞的。如果您的程序使用阻塞套接字,那么这很好,但是如果您使用非阻塞套接字,那么据我所知,您只有两个选择:
有组件
TTcpServer
和TTcpClient
可以在阻塞和非阻塞之间切换。但是,如果您在非阻塞模式下操作它们,它们就不起作用(基本操作因 WSAEWOULDBLOCK 失败)并且没有解决方法。请注意,阅读本文的其他人可能不知道:即使在最新版本(如我所写)中,您仍然可以通过将
dclsocketsNNN.bpl
添加到设计时包列表中来将它们导入 IDE 。它们在那里,只是默认情况下不活动。就我个人而言,我仍然在生产中以非阻塞模式使用 TClientSocket,它工作得很好(在修复了一些错误之后,这可能要归功于提供了完整的源代码!)
They have been deprecated in favour of Indy sockets.
However, Indy sockets are blocking-only. If your program used blocking sockets then this is fine, however if you are using non-blocking sockets, then as far as I am aware you only have two options:
There are components
TTcpServer
andTTcpClient
which have a toggle between Blocking and Non-blocking. However, if you operate them in non-blocking mode, they just don't work (basic operations fail with WSAEWOULDBLOCK) and there is no workaround.Note for anyone else reading this who may be unaware: even in the latest versions (as I write), you can still import them into the IDE by adding
dclsocketsNNN.bpl
into the list of design-time packages. They are there, just not active by default.Personally I still use TClientSocket in non-blocking mode in production, it works just fine (after fixing some bugs, which is possible thanks to the fact that the full source is provided!)