Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Server code
- local modem = peripheral.wrap("back") -- Assuming the modem is on the back of the computer
- -- Unique identifier for this computer
- local myID = os.getComputerID()
- -- Function to broadcast a message to all connected clients except the sender
- local function broadcast(channel, message, sender)
- modem.transmit(channel, channel, {message = message, sender = myID})
- end
- -- Ask the user to configure the channel
- print("Enter the channel number to listen on:")
- local channel = tonumber(read())
- -- Open the channel
- modem.open(channel)
- print("Listening on channel " .. channel)
- -- Main loop
- while true do
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if senderChannel == channel then
- if message.sender ~= myID or message.sender ~= message.sender then
- print("Received: " .. message.message)
- broadcast(channel, message.message, message.sender)
- else
- print("Ignoring message from self.")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement