Networking

Functions

muse_boolean muse_network_startup (muse_env *env)
 In the POSIX version, we initially setup to block the SIGPIPE signal.
muse_cell fn_wait_for_input (muse_env *env, void *context, muse_cell args)

Point to point communication

Made possible through the functions



muse_cell fn_open_connection (muse_env *env, void *context, muse_cell args)
muse_cell fn_with_incoming_connections_to_port (muse_env *env, void *context, muse_cell args)

Multicast messaging

A simple multicast mechanism is implemented using UDP datagrams.

You join a multicast group by creating a muSE port using the function multicast-group. Once the join succeeds, you can broadcast a message to the group and can receive broadcast messages from any member of the group using the standard read and write functions.

Immediately after a read, information about the sender is stored internally and you can reply to the sender alone by using the reply function. reply works only with multicast group ports. It is a programming error to use it with other ports.

You can use the wait-for-input function to wait for a message from a multicast group as well.



muse_cell fn_multicast_group (muse_env *env, void *context, muse_cell args)
muse_cell fn_reply (muse_env *env, void *context, muse_cell args)
muse_cell fn_multicast_group_p (muse_env *env, void *context, muse_cell args)

Function Documentation

muse_boolean muse_network_startup ( muse_env env  ) 

In the POSIX version, we initially setup to block the SIGPIPE signal.

The SIGPIPE signal will be sent if we try to write into a socket whose read end has closed. This behaviour, when not masked out, causes the server to exit, and we don't want that to happen.

send() should then return EPIPE, which will be transformed into an IOException class.

More info can be found at - Unix-socket-faq Unix programming FAQ

muse_cell fn_open_connection ( muse_env env,
void *  context,
muse_cell  args 
)
 (open-connection "server.somewhere.com" port)
 (open-connection "231.41.59.26" 31415) 

Opens a TCP connection to the given server on the given port and returns a port object using which you can communicate with the server. The port can be closed by calling (close p). If a port number is omitted, 31415 (= MUSE_DEFAULT_MULTICAST_PORT) is used as the default.

Supports the

References muse_add_recent_item(), MUSE_NIL, MUSE_PORT_READ_WRITE, muse_raise_error(), MUSE_SYMBOL_CELL, muse_unicode_to_utf8(), and port_close().

muse_cell fn_with_incoming_connections_to_port ( muse_env env,
void *  context,
muse_cell  args 
)
 (with-incoming-connections-to-port port-number service-fn) 

Listens for connections to the given port and invokes the service function with the connection information..

 (with-incoming-connections-to-port 1234
   (fn (port client-info)
      ...)
   (fn ()   ; The "OnListening" function.
      ...))

If the service function returns (), the server is terminated, otherwise the server will accept the next connection and service it.

Parameters:
port-number The port-number can be one of a few things -

  • An integer giving the port number on which to accept connections from any internet address.
  • A string such as "12345" giving a port number serving the same prupose as above.
  • A string of the form "1.2.3.4:12345" where the portion before the colon ':' gives the IP address from which connections are accepted and the portion after the colon gives the port number on which connections are accepted. For example, if you pass "127.0.0.1:12345", then the server will only accept connections from the local machine on the port 12345.
See also:
fn_open_connection()

References muse_apply(), MUSE_INT_CELL, muse_list(), MUSE_NIL, muse_pop_recent_scope(), MUSE_PORT_READ_WRITE, muse_push_recent_scope(), muse_raise_error(), MUSE_TEXT_CELL, and muse_unicode_to_utf8().

muse_cell fn_wait_for_input ( muse_env env,
void *  context,
muse_cell  args 
)
 (wait-for-input network-port [timeout-microseconds]) 

Returns T if input is available and 'timeout if the wait timed out. Returns () upon error. Works only for network ports. It won't wait for file-based ports.

References _t, MUSE_NIL, MUSE_TIMEOUT, and muse_functional_object_t::type_info.

muse_cell fn_multicast_group ( muse_env env,
void *  context,
muse_cell  args 
)
 (multicast-group [address] [port]) 

Creates a port that represents a multicast group. You can send messages to the group by writing to the port and you can receive messages to the group by reading from the port. Loopback is disabled, so you won't receive your own messages. If you don't specify the port, the port 31415 is used. If you don't specify the address as well, the group address "231.41.59.26" is used.

Note that you should use relatively small expressions. The safest expressions are those that fit within about 512 bytes. If you use multicast-groups like you use SMS, you'll be fine. If you give too large a message, then the write will fail and return () and no message will be sent. You can check for the condition, therefore, at runtime.

You should only use multicast group addresses in the range - 225.0.0.0 to 231.255.255.255. For details, see http://www.iana.org/assignments/multicast-addresses

muse_cell fn_reply ( muse_env env,
void *  context,
muse_cell  args 
)
 (reply port) 

Immediately after a multicast read succeeds, you have the chance to reply specifically to that client. This is possible because the sender's information is stored in the multicast port structure.

References MUSE_NIL, muse_pwrite(), and port_putc().

muse_cell fn_multicast_group_p ( muse_env env,
void *  context,
muse_cell  args 
)
 (multicast-group? p) 

Returns p if it is a multicast port and MUSE_NIL if it isn't.

References MUSE_NIL, and muse_functional_object_t::type_info.

Generated on Fri Jun 18 14:49:38 2010 for muSE by  doxygen 1.6.3