Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'socket'
- gs = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
- sockaddr = Socket.sockaddr_in(8080, '0.0.0.0')
- gs.bind(sockaddr)
- gs.listen(5)
- socks = [gs]
- loop do
- nsock = select(socks)
- next if nsock == nil
- for s in nsock[0]
- if s == gs
- socks.push(s.accept.first)
- print(s, " is accepted\n")
- else
- if s.eof?
- # nc -vz localhost 1296
- print(s, " is gone\n")
- s.close
- socks.delete(s)
- else
- p :come
- # nc localhost 1296
- # してhoge エンターでおうむ返し
- str = s.gets
- s.write(str)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment