Finding an existing socket

jdpjamesp

ProgressTalk.com Moderator
Staff member
Hi - a question about socket connections in Progress.

We use server sockets to connect to a couple of things in our software. This all works very well, until you try and startup a second instantiation of the software. At that point you get messages to say that the TCP port is already busy. We've had a look at using SESSION:FIRST-SERVER-SOCKET to try and connect to the same server socket, but sadly this isn't possible as the second instantiation of the software is on a different session.

Does anyone know if it's possible to query the TCP port somehow to see if it's in use and connect to the same server socket that is already in use?

Hope this question makes sense!

Cheers
 
The ENABLE-CONNECTIONS method returns logical value. Could you use a no-error on the method and then trap for the error or test for the return expression?
 
The ENABLE-CONNECTIONS method returns logical value. Could you use a no-error on the method and then trap for the error or test for the return expression?

Code:
DEFINE VARIABLE hSvrSocket  AS HANDLE      NO-UNDO.
DEFINE VARIABLE lOK         AS LOGICAL     NO-UNDO.

CREATE SERVER-SOCKET hSvrSocket.
hSvrSocket:SET-CONNECT-PROCEDURE('GotSocketData') NO-ERROR.

lOK = hSvrSocket:ENABLE-CONNECTIONS('-S 16996') NO-ERROR.

IF NOT lOK THEN
  MESSAGE 'Bugger! Guessing the port is in use.' 
    VIEW-AS ALERT-BOX ERROR.
ELSE
DO:

  WAIT-FOR READ-RESPONSE OF hSvrSocket.
  hSvrSocket:DISABLE-CONNECTIONS().
END.   

DELETE OBJECT hSvrSocket.

PROCEDURE GotSocketData.
  
  RETURN.
END PROCEDURE.

Hope I understood your problem hoped above code helps.
 
Hi Cecil,

thanks - we've already got something like that in place. What I was trying to say is that rather returning an error, to actually connect to the socket that's currently in use by the other session. Otherwise the socket functions would only work in instance 1, and instance 2 would be stuck.
 
If I understand you correctly, your server program is unable to handle multiple inbound connections. So the first session connects OK. Second session connects and fails (because the port is busy).

I have seen in the OpenEdge programmers guide when a server socket receives an inbound connection it implicitly created creates an additional server socket freeing up the port again, thus allowing multiple inbound connections.
 
Ah I understand the problem - it's an outbound server socket - so our application is querying data over TCP.
 
Back
Top