ramu
ramu

Reputation: 1029

Reusing socket handle

We have a legacy vb6 automation application that communicate over a sockets on need basis. But opening and establishing connection (only when required) to the remote port taking more time frequently.

So,i am planning to write other application (say a socket server) that opens the required sockets and keep the connections alive.This application will write connected socket handle values to a file or database.

Is it possible in vb6 to create a socket object using socket handle from the already opened socket that was owned by other process (socket server application in this case)?

Upvotes: 0

Views: 851

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 596277

This is exactly the type of situation that WSADuplicateSocket() is intended for.

Your "server" can create a socket and use WSADuplicateSocket() to fill a WSAPROTOCOL_INFO record that describes the socket. The "server" can then expose the WSAPROTOCOL_INFO to your VB app using any IPC mechanism you want. The VB app can pass the WSAPROTOCOL_INFO to WSASocket() to access the socket and use it as needed.

Upvotes: 2

Dark Falcon
Dark Falcon

Reputation: 44181

No, Windows sockets cannot be shared cross-process, not even through handle inheritance (this is because although it is usually a handle, an LSP might return something that is not a handle and thus not inherited). You should make one process open and maintain the connection and the others talk to that process to communicate with the server.

Upvotes: 2

Related Questions