An interface to User Datagram Protocol sockets.
(use udp) (begin (define s (udp-open-socket)) (udp-bind! s #f 0) (udp-connect! s "localhost" 13) ; daytime service (udp-send s "\n") (receive (n data from-host from-port) (udp-recvfrom s 64) (print* n " bytes from " from-host ":" from-port ": " data)) (udp-close-socket s)) ;; Prints the following: ;; 26 bytes from 127.0.0.1:13: Wed Dec 24 11:53:14 2003
Category 5, with several enhancements by Daishi Kato
This egg is hosted on the CHICKEN Subversion repository:
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
Returns a new UDP socket object.
Returns a new nonblocking UDP socket object.
- udp-bind! SOCKET HOST PORTprocedure
Binds a UDP socket to an address and port as specified by HOST and PORT. HOST may be a string consisting of an IP address or hostname, or #f, in which case INADDR_ANY is used. If PORT is 0, a port will be allocated by the system automatically.
- udp-connect! SOCKET HOST PORTprocedure
Connect a socket. In the case of UDP this does nothing more than associate a peer address with the socket in the kernel for use with later calls to send(2). UDP is a connectionless protocol.
- udp-send SOCKET STRINGprocedure
Send the bytes in STRING through SOCKET to its peer, as specified with a previous call to udp-connect!. If the socket is not connected, the system will return an error.
- udp-sendto SOCKET HOST PORT STRINGprocedure
Send the bytes in STRING through SOCKET to PORT on HOST.
- udp-recv SOCKET LENGTHprocedure
Receive a packet and store the data in string of size LENGTH. Returns two values: the number of bytes received and the string consisting the message.
- udp-recvfrom SOCKET LENGTHprocedure
Same as udp-recv except that two additional values are returned: the host string and port number from which the packet was received.
- udp-close-socket SOCKETprocedure
Close a socket.
- udp-socket? THINGprocedure
Test whether THING is a UDP socket.
- udp-socket-fd THINGprocedure
If THING is a UDP socket, returns the file descriptor associated with the socket.
- udp-bound? SOCKETprocedure
Test whether a UDP socket is bound to a local address and port.
- udp-connected? SOCKETprocedure
Test whether a peer address and port has been associated with a UDP socket with a call to udp-connect!.
- udp-bound-port SOCKETprocedure
Returns the port to which the socket is bound.
- udp-set-multicast-interface SOCKET ADDRESSprocedure
Specify the ADDRESS of the interface to send a multicast packet. This procedure might not be needed if there is only one network interface.
- udp-join-multicast-group SOCKET ADDRESS GROUP #!optional JOINprocedure
Join a multicast GROUP with the interface of the ADDRESSS which can be #f for INADDR_ANY. If the optional argument JOIN is set and #f, the multicast group is dropped.
- 1.18: Ported to CHICKEN 5 [thanks to Vasilij Schneidermann]
- 1.18: Added procedure udp-socked-fd [Ivan Raikov, suggested by sethalves]
- 1.14: Ported to Chicken 4
- 1.12: Didn't include signal.h on UNIX [felix]
- 1.11: More Win32 support [Daishi Kato]
- 1.10: Multicast support [Daishi Kato]
- 1.9: Win32 socket-header fun
- 1.8: Hopefully succeeded in actually fixing that cygwin problem (which wasn't a cygwin problem after all, but a broken declaration of ##net#recvfrom)
- 1.7: Fixed cygwin problem [thanks to Daishi Kato]
- 1.6: #includes ws2tcpip.h instead of winsock2.h [Thanks to Graham Fawcett]
- 1.5: Small fix (uses srfi-18 unit, now)
- 1.4: udp-bound-port [Contributed by Daishi Kato]
- 1.3: Yet another bugfix for better Windows support by Daishi Kato
- 1.2: Daishi Kato fixed several bugs
Copyright (c) 2004, Category 5 All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.