From daeb8d3c8f0090d5459eb86f51bc822a1bce59bf Mon Sep 17 00:00:00 2001 From: David René Date: Wed, 28 Feb 2007 12:17:19 +0000 Subject: [PATCH] add udp sender for the muscle message --- anubis_dev/library/system/muscle.anubis | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/anubis_dev/library/system/muscle.anubis b/anubis_dev/library/system/muscle.anubis index 14406b4..4f78248 100644 --- a/anubis_dev/library/system/muscle.anubis +++ b/anubis_dev/library/system/muscle.anubis @@ -24,13 +24,19 @@ public define Int32 _B_STRING_TYPE = 1129534546. // 'CSTR', public define Int32 _B_OBJECT_TYPE = 1330664530. // 'OPTR', // used for flattened objects public define Int32 _B_RAW_TYPE = 1380013908. // 'RAWT', // used for raw byte arrays -public define Int32 _CURRENT_PROTOCOL_VERSION = 1347235888. // 'PM00' -- our magic number 0x504D3030 +public define Int32 _CURRENT_PROTOCOL_VERSION = 1347235888. // 'PM00' -- our magic number 0x504D3030 + +public define Int32 _MUSCLE_MESSAGE_ENCODING_DEFAULT = 1164862256. //header for network transfert public type Message:... public define Maybe(Message) unflatten_message ( Data_IO io ). public define Maybe(ByteArray) flatten_message ( Message msg ). +public type Message_Send_Result: + flatten_error, + network_error, + ok. type Muscle_object: @@ -1514,6 +1520,58 @@ public define Maybe(ByteArray) String name )= find_raw(msg, name, 0). +/********************** I/O socket *****************************/ + + /** + * create the right udp socket. deterline if we must create broadcast + * or not udp socket + */ + +define Create_UDP_Client_Socket_Result + create_udp_socket + ( + Int32 ip, + )= + if ip = ip_address((255,255,255,255)) then + create_udp_client_broadcast_socket + else + create_udp_client_socket + . + + +public define Message_Send_Result + send_message_by_udp + ( + Message msg, + Int32 ip_address, // where you want to send the data + Int32 ip_port, + )= + if flatten_message(msg) is + { + failure then print("Error flattening identity Message"); flatten_error, + success(buffer) then + if create_udp_socket(ip_address) is + { + cannot_create_the_socket then network_error, + ok(socket) then + //the necessary UDP socket was created, hence we send the Message packet + with header = host_to_lendian_Int32_ByteArray(length(buffer)) + + host_to_lendian_Int32_ByteArray(_MUSCLE_MESSAGE_ENCODING_DEFAULT), + //send the header. that header is construct as follow (size of the following message + header mark) + if udp_send(socket, ip_address, ip_port, header) is + { + network_unreachable then network_error, + packet_sent then + //now we send the real message + if udp_send(socket, ip_address, ip_port, buffer) is + { + network_unreachable then network_error, + packet_sent then ok + } + } + } + }. + /********************** TESTING SERVER *************************/ -- libgit2 0.21.4