Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --requires
- local component = require("component")
- local event = require("event")
- local modem = component.modem
- --port
- local chatPort = 312
- modem.open(chatPort)
- --listen
- function doListen(localAddress, remoteAddress, port, distance, message)
- if(port ~= chatPort) then return end
- print(message)
- end
- --intro / input
- io.write("Welcome to GlobalChat!\nEnter a nickname: ")
- local nickname = io.read()
- io.write("Welcome, "..nickname..", you are now chatting with everyone else running this program(type /quit to exit).\n")
- event.listen("modem_message", doListen)
- modem.broadcast(chatPort, nickname .." has joined!")
- while true do
- local msg = io.read()
- if(msg == "/quit") then
- modem.broadcast(chatPort, nickname .." has quit!")
- break
- end
- modem.broadcast(chatPort, nickname ..": "..msg)
- end
- event.ignore("modem_message", doListen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement