indexing description: "[ A TCP server socket that listens at a port on all local interfaces for incomming connection attempts. ]" date: "$Date$" revision: "$Revision$" class EM_TCP_SERVER_SOCKET inherit EM_SOCKET EM_SHARED_SUBSYSTEMS export {NONE} all {ANY} Network_subsystem end EM_SHARED_ERROR_HANDLER export {NONE} all end NET2_FUNCTIONS_EXTERNAL export {NONE} all end create make feature {NONE} -- Initialization make is -- Initialise new server socket. do port := -1 is_open := False net2_socket_id := -1 create connection_accepted_event ensure not_open: not is_open port_not_set: port = -1 end feature -- Status setting open is -- Open server on `port'. do if Network_subsystem.sockets.is_port_free (port) then net2_socket_id := net2_tcpaccept_on_external (port) if net2_socket_id /= -1 then Network_subsystem.sockets.add_server (Current) is_open := True else Error_handler.raise_error (Error_handler.Em_error_tcp_open, [port]) end else Error_handler.raise_error (Error_handler.Em_error_tcp_open, [port]) end ensure then open: is_open end close is -- Close server. do net2_tcpclose_external (net2_socket_id) Network_subsystem.sockets.remove_server (Current) net2_socket_id := -1 is_open := False end feature -- Events connection_accepted_event: EM_EVENT_CHANNEL [TUPLE [EM_TCP_CLIENT_SOCKET]] -- Connection accepted event feature {EM_SOCKETS} -- Implementation handle_data_received is -- Handle data received event. do Error_handler.raise_error (Error_handler.Em_error_this_should_never_happen, ["EM_TCP_SERVER_SOCKET.handle_data_received"]) end handle_connection_accepted (a_client_socket: EM_TCP_CLIENT_SOCKET) is -- Handle connection accepted. do connection_accepted_event.publish ([a_client_socket]) end invariant connection_accepted_event_not_void: connection_accepted_event /= Void end