Creation Parameters

In order to receive data through sockets, you first need to create a wxSocketServer object to wait for new connections. Then, in an event handler, you need to create a new wxSocketServer object that will handle the connection, and set up an event handler for that socket, as well. Alternatively, you could call socket_accept() with wait = 1, although this will not return until a connection has been made.


     server = create( wxSocketServer, address )
     server_id = get_id( server )
     set_socket_notify( server, {wxSOCKET_CONNECTION_FLAG, wxSOCKET_LOST_FLAG})
     socket_event_handler( server, main_form, server_id )

     procedure main_socket_event( atom this, atom event_type, atom id, atom event )
         sequence bytes
         atom socket

         event_type = get_socket_event( event )

         if id = server_id and event_type = wxSOCKET_CONNECTION then
             connection = socket_accept( server, 0 )
             connection_id = get_id( connection )
             set_socket_notify( connection, {wxSOCKET_INPUT_FLAG, wxSOCKET_LOST_FLAG})
             socket_event_handler( connection_id, main_form, connection_id )
             set_event_handler( main_form, connection_id, wxEVT_SOCKET, routine_id("main_socket_event"))

         elsif event_type = wxSOCKET_LOST then
             delete_instance( socket_from_event( event ) )

         elsif event_type = wxSOCKE_INPUT then
             bytes = socket_read( socket_from_event( event ) )

         end if
     end procedure
     set_event_handler( main_form, server_id, wxEVT_SOCKET, routine_id("main_socket_event")



( atom socket, integer wait )

Category: wxSocketServer

Accepts an incoming connection request, and creates a new wxSocketBase object which represents the server-side of the connection.

If wait is TRUE and there are no pending connections to be accepted, it will wait for the next incoming connection to arrive. Warning: This will block the GUI.

If wait is FALSE, it will try to accept a pending connection if there is one, but it will always return immediately without blocking the GUI. If you want to use Accept in this way, you can either check for incoming connections with WaitForAccept or catch wxSOCKET_CONNECTION events, then call Accept once you know that there is an incoming connection waiting to be accepted.