Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modemSide = "top" -- Modify with your modem side
- rednet.open(modemSide)
- print("Server online. Waiting for connection...")
- local function acceptConnection()
- while true do
- local senderId, message = rednet.receive()
- if message == "connect" then
- print("Incoming connection from ID: " .. senderId)
- print("Do you want to accept this connection? (yes/no)")
- local input = read()
- if input == "yes" then
- rednet.send(senderId, "accepted")
- return senderId
- else
- rednet.send(senderId, "rejected")
- end
- end
- end
- end
- local function startShell(clientId)
- print("Connection accepted. Starting shell.")
- print("Type 'exit' to disconnect.")
- while true do
- io.write("> ")
- local input = read()
- if input == "exit" then
- rednet.send(clientId, "exit")
- print("Shell closed.")
- return
- else
- rednet.send(clientId, input)
- local _, message = rednet.receive(5) -- Timeout of 5 seconds
- if message then
- print(message)
- else
- print("No response from client.")
- end
- end
- end
- end
- local clientId = acceptConnection()
- if clientId then
- startShell(clientId)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement