Open Socket Question

Dave dave at looktowindward.com
Thu Feb 28 05:24:43 CST 2008


On 27 Feb 2008, at 16:40, Alex Tweedly wrote:

> Dave wrote:
>>
>> 3)  In my App, a Server is only allowed to Accept connections from  
>> Certain Clients (this is controlled by the IP Address and a Value  
>> passed to the Server in the Connection Request).  This is my  
>> Accept code:
>>
>> function IStartServer theServerPortNumber
>>
>>   --
>>   --  Accept Connection(s) from Client(s)
>>   --
>>   accept connections on theServerPortNumber with message  
>> "ISMServerContactedByClient"
>>
>>   return empty
>> end IStartServer
>>
>> on ServerContactedByClient theIPAddress
>>   local myResult
>>
>>   --
>>   --  Check for Error
>>   --
>>   put the result into myResult
>>   if myResult <> empty then exit ServerContactedByClient
>>   read from socket theIPAddress for kPacketCountSize chars with  
>> message "ISMServerReceivedPacketSize"
>>
>> end ServerContactedByClient
>>
>> Can I just look up "theIPAddress" in "ServerContactedByClient" and  
>> if it's not in the list of valid Clients, do do an "exit  
>> ServerContactedByClient" to ignore the request?
>>
>>
> That would kind of work, because you neither read from, nor write  
> to, the socket, so the connection isn't 'active'. However, the  
> connection will still be open, so you really ought to do "close  
> theIPAddress"    (btw, I think the documentation is misleading. It  
> says the parameter to the handler called when the connection is  
> open contains the IP Address, when in fact it contains the socket  
> descriptor - typically an IP Address and port, but sometimes IP  
> Addr + port + connectionID. I find it confusing to name that  
> parameter "theIPAddress"; I always call it pSocket :-).
>

The Server can "Accept" connections from a number of Clients, surely  
if I close the port, then no other clients will be able to connect.  
Or do you mean I should (on the Server) close the connection that is  
presented to the "ServerContactedByClient" handler? e.g. the IP/Port? 
ConnectionID of the Client?

> Also, I'm curious.This is probably just because you've snipped code  
> to send it here, but just in case it isn't ....
>
> you look at "the result" immediately - what do you expect it to  
> contain at that point ?

I think this was a snipping problem as you say, before I wasn't using  
a Callback Handler and so I needed to check the result after the  
command returned.  However, do need to check "the result" after the  
Accept command?:

   accept connections on theServerPortNumber with message  
"ServerContactedByClient"

Thanks a Lot
All the Best
Dave














More information about the use-livecode mailing list