TIP #391: SUPPORT FOR UDP SOCKETS IN TCL ========================================== Version: $Revision: 1.3 $ Author: Jeff Rogers State: Withdrawn Type: Project Tcl-Version: 8.7 Vote: Pending Created: Wednesday, 26 October 2011 URL: https://tip.tcl-lang.org391.html Post-History: Obsoleted-By: TIP #409 ------------------------------------------------------------------------- ABSTRACT ========== This proposal is to add UDP socket support to the core in a clean and unobtrusive way. RATIONALE =========== UDP is used for sending datagrams over the internet, which is an integral part of a number of protocols, notably including direct DNS queries in the majority of deployment. Thus, it is useful to be able have Tcl able to send and receive messages via UDP sockets, filling out a signficant missing feature. UDP sockets have the same basic needs as tcp sockets - creating, reading, writing. So it follows that they could be handled by the same basic commands. SPECIFICATION =============== The *socket* command should have a flag, *-udp*, added. This should work for both client and server sockets. *socket -udp* ?*-myaddr* /addr/? ?*-myport* /port/? /host port/ *socket -udp -server* /command/ ?*-myaddr* /addr/? /port/ To complement this, the sockets created by the above commands will have an additional configuration option, *-peeraddr*. This is a read/write option. It is used to set the peer address before a write, and to retrieve the peer address after a read. The peer address should persist until it is changed by a read or fconfigure. When used on a UDP socket, *puts* sends a single message (sendmsg). If the data is too large to fit in a single message then an error is raised. When reading from a udp socket, the data retuend will only ever be the contents of a single message in a single operation. Thus, *read* will return one entire message, and *read* with a bytecount or *gets* will read a new message into their buffer iff it is completely empty, and will return the requested data from that buffer. Readable and writable fileevents should work naturally. EXAMPLE USAGE =============== set udpsock [socket -udp 8.8.8.8 53] fconfigure $udpsock -peeraddr {8.8.8.8 53} puts $udpsock $packet set packet [read $udpsock] set peer [fconfigure $udpsock -peeraddr] COPYRIGHT =========== This document has been placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows