Julik
Julik

Reputation: 7856

Testing a real TCP Socket in Ruby

I have a program that operates on a socket via the Rack hijack. I would like to test that program using a real TCP socket, and I want to receive what it sends to the socket and check that I get the right results.

How do I go about this? I tried using Socketpair:

@sender, @receiver = Socket.pair(:INET, :STREAM, 1024 * 256)`

and then

hijack_proc = h.fetch('rack.hijack')
hijack_proc.call(@sender)

but all I get is Protocol not supported - socketpair(2)

Upvotes: 0

Views: 422

Answers (1)

Are you looking for Netcat? You should be able to use something like netcat -l 4444 in a terminal window, and give 4444 as the port to your program to connect to. Once your program sends something to Netcat, and you see it in your terminal, you can type your 'response' and press Enter to send that text back to your program.

Upvotes: 0

Related Questions