5 Cent tip for today [ UDP chat ]

Started by newdep, July 24, 2004, 02:19:20 AM

Previous topic - Next topic

newdep

2 programs running under linux which must have an ANSI/termcap

terminal running..Modify at wish :) If you would like to test it you could

send a message to crab.ath.cx 54054 and see if you get a reply.



*** NCHAT



#!/usr/bin/newlisp

;;

;; NCHAT & NCHATL version 1.0

;; Stripped down demo PromptMode version.

;;

;; nchat & nchatl are 2 programs that work together.

;;

;; nchat is the client which enables you to broadcast

;; or directly sent a message using UDP.

;;

;; nchatl is the listener which is seperate started

;; because (net-receive-udp) is blocking. Thus you

;; could start it like: "nchatl &" in the terminal

;; where you want to see the nchat messages coming in.

;;

;; nchat is the CLIENT talking to UDP port 54054

;; and uses the broadcast address 10.10.10.255,

;; please adjust to your network/subnet.

;;

;; Because is its an udp chat you will never know

;; if the messages arrived at the other end.

;;

;; keep in mind, switches in the network block

;; broadcasts often by default.

;;

;; If you want NO broadcast but direct UDP chat

;; then remove the "true" from (net-send-udp)

;; and set the address to the remote users. Where

;; a nchatl is running.

;;

;; Make sure you have installed on linux: tput

;;

;; Enjoy...

;;

;; Norman.

;;



(println "** Your are now in nchat, ctrl-c to quit **")



(set 'port 54054)

(set 'addr "10.255.255.255")



(until (net-error)

        (print "->")

        (set 'keyed (read-line))

        (net-send-udp addr port keyed true ))





*** NCHATL

#!/usr/bin/newlisp

;;

;;- nchat SERVER listening on UDP port 54054

;;

;; Start nchatl on the prompt like "nchatl &"

;; you will only see the udp messages where

;; in the terminal where yuo started nchatl.

;;

;; Make sure the 'port is the same as in nchat

;;

 

(set 'port 54054)

(set 'maxchars 100) ;; maximum character to display



(until (net-error)

        (if (set 'buff (net-receive-udp port maxchars )))



        ;; terminal control codes

        (! "tput sgr0")

        (! "tput sc 2")

        (! "tput cup 0 0")

        (! "tput setaf 9")

        (! "tput setab 1")

        (! "tput el")

        (println (nth 1 buff) " -> " (nth 0 buff))

        (! "tput rc"))

)



;; enjoy...
-- (define? (Cornflakes))