Loading ...
Sorry, an error occurred while loading the content.

RE: [eiffel_software] Sockets and timeouts

Expand Messages
  • Robert Jurjevic
    Dear Ulrik, The timeout you have set is used in the following features of the NETWORK_SOCKET (that is at least what I have concluded by inspecting the class
    Message 1 of 3 , Feb 1, 2005
    • 0 Attachment
      Dear Ulrik,

      The timeout you have set is used in the following features of the
      NETWORK_SOCKET (that is at least what I have concluded by inspecting the
      class text, i.e. the class source code)

      ready_for_reading: BOOLEAN is
      -- Is data available for reading from the socket
      within
      -- `timeout' seconds?
      local
      retval: INTEGER
      do
      retval := c_select_poll_with_timeout
      (descriptor, True, timeout)
      Result := (retval > 0)
      end

      ready_for_writing: BOOLEAN is
      -- Can data be written to the socket within
      `timeout' seconds?
      local
      retval: INTEGER
      do
      retval := c_select_poll_with_timeout
      (descriptor, False, timeout)
      Result := (retval > 0)
      end

      has_exception_state: BOOLEAN is
      -- Is socket in exception state within `timeout'
      seconds?
      local
      retval: INTEGER
      do
      retval := c_check_exception_with_timeout
      (descriptor, timeout)
      Result := (retval > 0)
      end

      so the timeout is basically used for reading from and writing to socket.
      In another words you can write something like

      if client_socket.ready_for_reading then
      client_socket.read_line
      end

      which would effectively read a 'line' form the client socket but will
      timeout after the timeout period if a 'line' does not appear on the
      socket within the time limit.

      The disconnection of the client is in principle a responsibility of the
      server. If server does not disconnect the client the client may stay
      connected 'forever'. Most servers disconnect their clients after a
      certain amount of inactivity. For example that is what chess servers do.
      You can, of course, disconnect form the server by simply closing the
      client socket whenever you desire. Of course, you should follow the
      client-server protocol.

      Hope this helps.

      Yours sincerely,

      Robert Jurjevic


      -----Original Message-----
      From: ulrik_sandquist [mailto:ulrik_sandquist@...]
      Sent: 31 January 2005 21:36
      To: eiffel_software@yahoogroups.com
      Subject: [eiffel_software] Sockets and timeouts




      Hi,

      Is there a way to enforce a timeout for client sockets (I'm using
      EiffelStuido 5.5 Free on Windows XP)? I'm writing a simple client/server
      application and need to to get rid of idling clients.

      There is a "set_timeout" command in NETWORK_SOCKET but it seems to have
      no effect, at least not the way I'm using it. Here is a code
      snippet:

      // server- and client sockets are both NETWORK_STREAM_SOCKETs
      server_socket.accept
      client_socket ?= server_socket.accepted
      if client_socket /= Void then
      client_socket.set_timeout (10) -- Seconds
      // ... do whatever ...

      Connecting as a client (telnet in this case) works fine, but I never get
      disconnected even if I go on holiday. Is there a way to achieve this?

      Regards,
      Ulrik S






      Yahoo! Groups Links








      _____________________________________________________________________
      This e-mail has been scanned for viruses by MCI's Internet Managed
      Scanning Services - powered by MessageLabs. For further information
      visit http://www.mci.com

      _____________________________________________________________________
      This e-mail has been scanned for viruses by MCI's Internet Managed Scanning Services - powered by MessageLabs. For further information visit http://www.mci.com
    • ulrik_sandquist
      ... Thanks, that did trick! This is more the Eiffel way of doing things I guess - a query returning rather than a command raising an exception (which was
      Message 2 of 3 , Feb 1, 2005
      • 0 Attachment
        --- In eiffel_software@yahoogroups.com, "Robert Jurjevic"
        <Robert.Jurjevic@B...> wrote:
        >[DELETED]
        > if client_socket.ready_for_reading then
        > client_socket.read_line
        > end
        >[DELETED]


        Thanks, that did trick!

        This is more the "Eiffel way" of doing things I guess - a query
        returning rather than a command raising an exception (which was
        sort-of what I expected). Quite neat.

        /Ulrik S
      Your message has been successfully submitted and would be delivered to recipients shortly.