This is my first post here, and if I have chosen the wrong spot, my
I wish to make a simple proxy server. It will accept incoming
connections and then connect to a pre-defined foreign address/port.
It needs to transmit the information as it comes in, even if that is
character by character (or byte by byte) and does not necessarily
include line feeds, but if there is a large amount of data received, it
should transmit it again all at once, after the modifications.
I would like to modifying some of the information before passing it on.
I am new to ruby programming, but I have dealt with PHP, C++, and C#
pretty extensively. Unfortunately, network programming has never been
I have come up with a few thoughts… Having the main thread accept the
incoming connection and create a new thread for the connection. that
thread would create a thread to handle user-to-server data and the
original thread would handle server-to-user data. If either sees a lost
connection, it would have to signal the other thread that it has
My concern on this approach is whether TCPSocket will freak out when
being read from 1 connection and written to by another, simultaneously.
I didn’t see a way to use TCPSocket to check if data was present or not.
There were methods named ‘nonblock’ but the examples they showed looked
like they blocked anyhow. So I couldn’t see a way to use just the
single thread to swap the data back and forth. (I can’t imagine it’s
not possible… Ruby is just too flexible to not have that.)
Or maybe there’s some way that I haven’t thought of?
I appreciate any input.