Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'socket'
- def read(sock)
- lenb = sock.readpartial(4)
- len = lenb.unpack("L")[0]
- lenb + sock.readpartial(len)
- end
- serv = TCPServer.new(1234)
- socket = serv.accept
- uplink = TCPSocket.new('192.168.0.2', 7777)
- loop do
- ret = IO.select([socket, uplink])
- if ret[0]
- ret[0].each do |s|
- buf = read(s)
- if socket == s
- puts ">> #{buf.inspect}"
- uplink.write(buf)
- end
- if uplink == s
- puts "<< #{buf.inspect}"
- socket.write(buf)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment