[Gambas-user] ServerSocket.Pause() and ServerSocket.Resume()?

T Lee Davidson t.lee.davidson at gmail.com
Thu Aug 27 00:11:18 CEST 2020


On 8/25/20 10:14 PM, Hans Lehmann wrote:
> Hello,
> 
> I have problems understanding how to use the two methods
> ServerSocket.Pause() and ServerSocket.Resume() in gb.net.
> In which cases does their use make sense or is even necessary? A small
> section of source code would help enormously.
> 
> The same applies to the ServerSocket.Timeout property: Who or what is
> time-limited?  Is this property set once or do you react to possible
> events of the class?
> 
> With kind regards
> 
> Hans

A socket timeout limits the amount of time that is allowed for communication between connections. This could be establishing a 
connection or sending data. It is used to prevent troublesome connections from usurping resources and to enhance security by 
closing abandoned connections. This property can be changed whenever necessary or prudent.

One case in which you might wish to pause new connections is when you need to do a large data transfer and want to give it 
priority to prevent new connections making the same type of data transfer request and flooding your server.

For a code example, you can download ServerSocket (and ClientSocket to test it) from the Software Farm near the bottom of the 
Examples section.

Add the following at line 111 (just before Socket_Write) of the Socket_Read event handler of ServerSocket:

   If sBuf = "start-massive-transfer" Then
     btnPause.Enabled = False
     Print "Doing massive transfer."
     MyServerSocket.Pause
     MyServerSocket.Timeout = 10 * 1000 ' Prevent this priority connection from keeping the others waiting too long
   Else If sBuf = "end-massive-transfer" Then
     Print "Massive transfer done."
     MyServerSocket.Timeout = 0
     If Not Waiting Then MyServerSocket.Resume ' Retain btnPause control of Pause/Resume state
     btnPause.Enabled = True
   Endif


-- 
Lee


More information about the User mailing list