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?
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.
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:
- use threads plus blocking Indy sockets
- use TClientSocket and TServerSocket
There are components TTcpServer
and TTcpClient
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!)
精彩评论