File: udp-server.lsp

package info (click to toggle)
newlisp 10.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 6,248 kB
  • sloc: ansic: 33,280; lisp: 4,181; sh: 609; makefile: 215
file content (27 lines) | stat: -rw-r--r-- 816 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env newlisp

; demo server for non-blocking UDP communications
;
; Start this program then start the client udp-client.lsp
;
; Note, that net-listen in UDP mode only binds the socket
; to the local address, it does not 'listen' as in TCP/IP.
;
; On Windows the received string for the remote host also contains
; the port separated by a colon and must parsed out. On UNIX this
; is not necessary.
; v.1.0
; v.1.1 made it work for Windows parseing out the host label


(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))
(exit)
;; eof