Issue with TSOCKET()

Issue with TSOCKET()

Postby paulrogers » Tue Jan 13, 2015 11:28 am

Hi All,

I am getting an issue when I am trying to connect to 2 different IP / Port / Sockets.

To give a small idea of the background, I am trying to read two different reader heads for scales on two different IP/Port locations, from a single machine.

The system is setting up the 2nd connection correctly (and the Tsocket:New() seems to connect, but I get the following error (in the DEBUG log) when attempting the :SendData


13/01/2015 10:50:01: Connect Socket handle: 624
13/01/2015 10:50:01: Write Socket handle: 624
13/01/2015 10:50:21: Read Socket handle: 624
13/01/2015 10:50:21:  0104028001000000.kg 9900177

13/01/2015 10:50:33: Connect Socket handle: 896
13/01/2015 10:52:09: Sent: -1 Len: 10 Buffer Len: 0 Error: 10057
13/01/2015 10:52:09: Sent: -1 Len: 10 Buffer Len: 0 Error: 10057
13/01/2015 10:52:09: Sent: -1 Len: 10 Buffer Len: 0 Error: 10057
13/01/2015 10:52:09: Sent: -1 Len: 10 Buffer Len: 0 Error: 10057
......... Ad-infinitum


Effectively the code is the following for the Two Bridges (oSocketArray is an array for the two bridges)

IF EMPTY(oSocketArray[nBridge])
mUniWinConnected := .F.
mUniWinClosed := .F.
mUniWinInput := ""
oSocketArray[nBridge] := TSocket():New(UniPort)
mTimer := 0
UniWinSocket := oSocketArray[nBridge]:nSocket
oSocketArray[nBridge]:bRead = { | oSocket | mUniWinInput := oSocket:GetData() }
// Never use a MsgInfo() here because it hangs Windows!!!
oSocketArray[nBridge]:bConnect = { || mUniWinConnected := .T. }
oSocketArray[nBridge]:bClose = { || mUniWinClosed := .T. }
oSocketArray[nBridge]:lDebug = .T.
oSocketArray[nBridge]:cLogFile = "iplogfile.log"
oSocketArray[nBridge]:Connect( ALLTRIM(cIpAddr) ) // use the server IP address here
mUniIp := ALLTRIM(cIpAddr)
ENDIF

RetCode := oSocketArray[pBNumber]:SendData( str_send )
RetCodeData := oSocketArray[pBNumber]:GetData()


The system never gets beyond the SendData command and at this point, the .exe remains in memory and running the command ad-infinitum

13/01/2015 10:52:09: Sent: -1 Len: 10 Buffer Len: 0 Error: 10057


I never do a :Close() or :End() on the initial socket, but when I did try this, it still failed with the same error

Any help would be greatly appreciated.

Paul Rogers
paulrogers
 
Posts: 4
Joined: Tue Mar 18, 2014 10:53 am

Re: Issue with TSOCKET()

Postby Antonio Linares » Wed Jan 14, 2015 5:43 am

Paul,

You are getting an error 10057. Please review its meaning here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668%28v=vs.85%29.aspx

WSAENOTCONN
10057
Socket is not connected.
A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using sendto) no address was supplied. Any other type of operation might also return this error—for example, setsockopt setting SO_KEEPALIVE if the connection has been reset.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Issue with TSOCKET()

Postby paulrogers » Wed Jan 14, 2015 12:11 pm

Hi Antonio,

I full understand the meaning of the error, it's just that the TSocket Commands do not seem to be working correctly for Closing and Ending the socket connection. If I close() and end() and then retry to open the Connection (using the same details), then the "SendData" command just re-iterates the error ad-infinitum.

Is there a guide to the Return codes from Tsocket:Connect() function? I seem to get a return code of "10" for everything, which - again - doesnt seem to indicate anything.

Paul Rogers
paulrogers
 
Posts: 4
Joined: Tue Mar 18, 2014 10:53 am

Re: Issue with TSOCKET()

Postby Antonio Linares » Wed Jan 14, 2015 2:23 pm

Paul,

Tsocket:Connect() is just a wrapper to sockets function connect():

http://msdn.microsoft.com/en-us/library/windows/desktop/ms737625%28v=vs.85%29.aspx

See the FWH source code for it:

Code: Select all  Expand view  RUN
HB_FUNC( CONNECTTO )  // nSocket, nPort, cIPAddr --> nReturnCode
{
   SOCKADDR_IN sa; // sockaddr_in sa;

   memset( ( char * ) &sa, 0, sizeof( sa ) );

   sa.sin_family      = AF_INET;
   sa.sin_port        = htons( ( u_short ) hb_parni( 2 ) );
   sa.sin_addr.s_addr = inet_addr( hb_parc( 3 ) );

  hb_retnl( connect( hb_parni( 1 ), ( SOCKADDR * ) &sa, sizeof( sa ) ) );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 70 guests