Guest User

Untitled

a guest
Jan 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. require 'socket'
  2.  
  3. def read(sock)
  4. lenb = sock.readpartial(4)
  5. len = lenb.unpack("L")[0]
  6. lenb + sock.readpartial(len)
  7. end
  8.  
  9. serv = TCPServer.new(1234)
  10.  
  11. socket = serv.accept
  12. uplink = TCPSocket.new('192.168.0.2', 7777)
  13.  
  14. loop do
  15. ret = IO.select([socket, uplink])
  16. if ret[0]
  17. ret[0].each do |s|
  18. buf = read(s)
  19. if socket == s
  20. puts ">> #{buf.inspect}"
  21. uplink.write(buf)
  22. end
  23.  
  24. if uplink == s
  25. puts "<< #{buf.inspect}"
  26. socket.write(buf)
  27. end
  28. end
  29. end
  30. end
Add Comment
Please, Sign In to add comment