c++builderc++builder-10-seattle

Using Web.Win.Sockets in C++ Builder 10 Seattle


I have an existing (large) project that was originally built using C++ Builder 2010. It uses the now deprecated sockets for communication.

I read that they were still available in a sample project and built it from the command line. I navigated to the the bpl in the sample folder from Component/Install Packages and installed it and went on to try and get the code going. But I get a feeling some step is missing.

Including Web.Win.Sockets.hpp from the sample folder does not seem to be enough. It seems to not contain definitions regarding a lot of things, like for example TServerSocket etc that the existing code uses. System.Win.ScktComp seems to include these missing definitions but mixing both doesn't seem like the right thing to do. Just for fun I tried some crazy thing like that once and got it to compile, but data transmitted seemed to include garbage that messed up the communication.

At one point I tried moving to the components in System.Win.ScktComp instead but there was no good info about what correlated to what and if there were any caveats. After I got the program to compile it would not be able to connect etc.

So, is there any good guide to enabling and using the "old" sockets for C++ Builder 10 Seattle? And if one were to move to the new ones, is it a drop in replacement or would it require a lot of work? The system transmits a lot of data in a custom binary format so a lot of stream handling is done etc. Right now I need to get this up and running so a large re-write of those parts is not feasible at this moment.


Solution

  • Web.Win.Sockets and System.Win.ScktComp are not the same thing, and are not drop-in replacements for each other.

    System.Win.ScktComp contains the old VCL socket components (TClientSocket, TServerSocket, etc). This is the one you want.

    Web.Win.Sockets contains the old CLX socket components (TTcpClient, TTcpServer, etc). You don't want this one, so ignore the sample project, you don't need it.

    To get the VCL sockets components, all you need to do is install the dclSockets package that is in your $(BDS)\bin folder, like the documentation says:

    Installing Socket Components

    The socket components are not installed by default. To use the socket components, you must install the dclsockets<.bpl> package.

    To install the socket components:

    1. Select Component > Install Packages.
    2. In the Install Packages dialog box, click Add.
    3. In the Add Design Package dialog, browse to C:\Program Files (x86)\Embarcadero\Studio\17.0\bin.
    4. Select dclsockets230.bpl, and click Open.
    5. Click OK to dismiss Install Packages dialog.
    6. The socket components (TClientSocket and TServerSocket) are listed in the Internet category of the Tool Palette.

    Note: These steps are one-time installation instructions. The socket components should be available for all future projects.

    If you want to switch your code to different socket components in the future, you will have to re-write your socket code accordingly.