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) |
| 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
(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().
(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.
| port-number | The port-number can be one of a few things -
|
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().
(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.
(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
(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().
(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.
1.6.3