Alaska Software Inc. - How to "test" a socket ?
Username: Password:
AuthorTopic: How to "test" a socket ?
Jose Adriano Baltieri How to "test" a socket ?
on Wed, 08 Aug 2007 09:43:01 -0300
I have a server application , which has an array of socket numbers.

Each element as a socket number that has been previously connected to this server.

I need to search across this array and test the situation of all the connected 
sockets BEFORE I cand send information to any of them.

IOW, I just need to check if one of theses sockets is good (client is still 
connected) or not.

What's the best way of doing it, considering perfomance ?

After I have a "good" socket at hand, I'll send to it but, when I send, I need 
to be SURE that the socket IS OK.

Thanks in advance 4 your support !
Raffaele tammeoA possible solution
on Wed, 08 Aug 2007 16:48:02 +0200
hallo Jose
usually i do like this:

the first time i must send the data, i usually test the socket:

nWritten := SocketSend(nSocketSend, "hallo", ,  ,  @nError)
if (nWritten <> 5)
  msgbox("I wrote " + alltrim(str(nWritten)) + " bytes, not 5")
else
  msgbox("Error:" + alltrim(str(@nError)))
endif

i never found something best
could it be good?
best regards

Raffaele


"Jose Adriano Baltieri" <jabaltie@unimep.br> ha scritto nel messaggio 
news:756ea9f3$3930f9c6$1054ec@news.alaska-software.com...
>I have a server application , which has an array of socket numbers.
>
> Each element as a socket number that has been previously connected to this 
> server.
>
> I need to search across this array and test the situation of all the 
> connected sockets BEFORE I cand send information to any of them.
>
> IOW, I just need to check if one of theses sockets is good (client is 
> still connected) or not.
>
> What's the best way of doing it, considering perfomance ?
>
> After I have a "good" socket at hand, I'll send to it but, when I send, I 
> need to be SURE that the socket IS OK.
>
> Thanks in advance 4 your support !
Jose Adriano Baltieri Re: A possible solution
on Wed, 08 Aug 2007 16:52:09 -0300
Raffaele tammeo wrote:
> hallo Jose
> usually i do like this:
> 
> the first time i must send the data, i usually test the socket:
> 
> nWritten := SocketSend(nSocketSend, "hallo", ,  ,  @nError)
> if (nWritten <> 5)
>   msgbox("I wrote " + alltrim(str(nWritten)) + " bytes, not 5")
> else
>   msgbox("Error:" + alltrim(str(@nError)))
> endif
> 
> i never found something best
> could it be good?

Hello Raffaele !

The problem is that I do not want to send anything BEFORE I know that the 
socket is OK.

Cause, on the other side, when data is received, it will be processed.

Also , there are syncronization issues.

What I did here is something similar : I receive on a non-blocking mode and, 
if I have an error while receiving, I know that the socket is not ok.

Of course I dont expect to receive ANYTHING and, since the receive will not 
block, I will just pass through the receive function without actually doing 
anything.

But I didnt think this was a nice way to solve it.

Think there could be a better approach.

Anyway, thanks for your help !

Ciao ! (?) or

Tchau (In portuguese) or

Bye

> best regards
> 
> Raffaele
Günter Beyes Re: How to "test" a socket ?
on Mon, 13 Aug 2007 11:28:14 +0200
Hello José,

> I just need to check if one of theses sockets is good (client is still 
> connected) or not.
> 
> What's the best way of doing it, considering perfomance ?

not sure if that's the best way, but getpeername() and its ASINET
equivalent should do it.

Regards,
Günter