Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Oct 17, 2019 5:01 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: ServerSocket example
PostPosted: Thu Jul 12, 2012 12:25 am 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
As a beginner with the TCP stuff I have a couple of questions about the ServerSocket example that comes with the default install of RS.

1. Why does the ServerSocket show a number of "Added Socket" messages (eleven on my PC) as soon as I click on the "Listen" button?

2. How do I send a message to a specific socket connected to the ServerSocket? I mean can I do something like "TCPSocket(n).write..." from outside the events of the ClientSocket instance?

Regards,
- Oskar


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket example
PostPosted: Thu Jul 12, 2012 2:08 am 
Offline

Joined: Tue Feb 14, 2012 5:39 am
Posts: 99
Location: Austria
You could either search in the ServerSocket.ActiveConnections() array for the wanted socket, or save the socket on creation.

If you want to attach information to the sockets, then you could subclass the TCP Socket and use that subclass when a socket is requested.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket example
PostPosted: Thu Jul 12, 2012 2:13 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
1. The ServerSocket maintains a pool of unused sockets so it can respond to incoming connections quickly. It doesn't want to have to construct a socket in order to handle a connection. It would be unable to handle another connection during the time it takes to construct the socket, so it hands off the connection to a premade socket so it can get back to listening and not appear "busy" to a potential connection request.

2. You would have to create some mechanism to identify the socket you want to talk to. You can't rely on an array index, the connections will be fluid. The best thing to do is subclass TCPSocket and add your own properties. Return an instance of your subclass in the AddSocket event. Then whenever you need to send a message outside the socket subclass, you can get a list of the current sockets from ActiveConnections, cast each one in turn as your subclass so you can access your special properties, and find the one you want. Then call Write to send the message.


Top
 Profile  
Reply with quote  
 Post subject: Re: ServerSocket example
PostPosted: Thu Jul 12, 2012 2:07 pm 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
Thanks a lot guys: your input really helped me understand how the ServerSocket actually works!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group