I used (net-receive-from) to make a little UDP proxy under linux. When I ran it under windows, it unexpectedly didn't work.
It seems that under Windows (XP), the address field which is returned is in the form ip-address:port.
portability issue with net-receive-from
Re: portability issue with net-receive-from
Yes, this is correct and must be watched for when extracting host strings from received UDP messages.It seems that under Windows (XP), the address field which is returned is in the form ip-address:port.
A second thing to watch for is the fact that both, the receiver and the sender must issue net-listen commands. When using UDP, net-listen only binds the socket used, it does not really listen as when using the TCP/IP protocol. The following code will work on both, Unix and Windows.
Server:
Code: Select all
; server - start first
(set 'socket (net-listen 10001 "localhost" "udp"))
(if socket (println "server listening on port " 10001)
(println (net-error)))
(while (not (net-error))
(set 'msg (net-receive-from socket 255))
(println "->" msg)
(net-send-to
(first (parse (nth 1 msg) ":")) (nth 2 msg) (upper-case (first msg)) socket))
Code: Select all
; client
(set 'socket (net-listen 10002 "" "udp"))
(if (not socket) (println (net-error)))
(while (not (net-error))
(print "enter something -> ")
(net-send-to "127.0.0.1" 10001 (read-line) socket)
(net-receive socket buff 255)
(println "=> " buff))
http://www.newlisp.org/downloads/develo ... nprogress/