Guest User

Untitled

a guest
Oct 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. require 'socket'
  2.  
  3. gs = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
  4. sockaddr = Socket.sockaddr_in(8080, '0.0.0.0')
  5. gs.bind(sockaddr)
  6. gs.listen(5)
  7.  
  8. socks = [gs]
  9.  
  10. loop do
  11. nsock = select(socks)
  12. next if nsock == nil
  13. for s in nsock[0]
  14. if s == gs
  15. socks.push(s.accept.first)
  16. print(s, " is accepted\n")
  17. else
  18. if s.eof?
  19. # nc -vz localhost 1296
  20. print(s, " is gone\n")
  21. s.close
  22. socks.delete(s)
  23. else
  24. p :come
  25. # nc localhost 1296
  26. # してhoge エンターでおうむ返し
  27. str = s.gets
  28. s.write(str)
  29. end
  30. end
  31. end
  32. end
Add Comment
Please, Sign In to add comment