# Simple http proxy, TCPServer\<-\>TCPSocket-\>

**URL:** <https://rubytalk.org/t/simple-http-proxy-tcpserver-tcpsocket/65095>\
**Category:** ruby-talk\
**Created:** [21 March 2012 12:12 UTC](https://rubytalk.org/t/simple-http-proxy-tcpserver-tcpsocket/65095 "2012-03-21T12:12:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [21 March 2012 12:12 UTC](https://rubytalk.org/t/simple-http-proxy-tcpserver-tcpsocket/65095/1 "2012-03-21T12:12:58Z")

</div>

Bigmac Turdsplash wrote in post #1052529:

> this thing kind of works... i have connected my webbrowser to 8181 for  
> testing... im looking for help, everything i try produce the same  
> resaults... i dont really want to bother with event machines

And what exactly do you need help with?

Cheers

robert

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [23 March 2012 00:54 UTC](https://rubytalk.org/t/simple-http-proxy-tcpserver-tcpsocket/65095/2 "2012-03-23T00:54:13Z")

</div>

Robert Klemme wrote in post #1052606:

> Bigmac Turdsplash wrote in post #1052529:
> 
> > this thing kind of works... i have connected my webbrowser to 8181 for  
> > testing... im looking for help, everything i try produce the same  
> > resaults... i dont really want to bother with event machines
> 
> And what exactly do you need help with?
> 
> Cheers
> 
> robert

so, my code has a few problems, the web browser will only load a few  
pages and the connection will always stay open as if the browser is  
waiting for more data...

i was thinking maybe i need 2 or 3 threads to handle both sides...

Thread.start{ receive\_get from webbrowser }#step one  
Thread.start{ send\_get to webserver } #step two  
Thread.start{ send\_response to webbrowser }#step three

if i understand, the first step i need to gather a host: field  
then establish a connection to the host web server  
and pass the response back to the web client...

i think my loops are wrong...

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [23 March 2012 11:10 UTC](https://rubytalk.org/t/simple-http-proxy-tcpserver-tcpsocket/65095/3 "2012-03-23T11:10:13Z")

</div>

Bigmac Turdsplash wrote in post #1052885:

> Robert Klemme wrote in post #1052606:
> 
> > Bigmac Turdsplash wrote in post #1052529:
> > 
> > > this thing kind of works... i have connected my webbrowser to 8181 for  
> > > testing... im looking for help, everything i try produce the same  
> > > resaults... i dont really want to bother with event machines

> so, my code has a few problems, the web browser will only load a few  
> pages and the connection will always stay open as if the browser is  
> waiting for more data...

A few things:

- Better use #read and #write for your IO  
- I think you are not properly implementing the HTTP proxy protocol.  
- You can make your life easier by using #gets("\r\n") to read HTTP  
request from client

> i was thinking maybe i need 2 or 3 threads to handle both sides...
> 
> Thread.start{ receive\_get from webbrowser }#step one  
> Thread.start{ send\_get to webserver } #step two  
> Thread.start{ send\_response to webbrowser }#step three

I don't think you'll necessarily need threads for HTTP 1.0.

> if i understand, the first step i need to gather a host: field  
> then establish a connection to the host web server  
> and pass the response back to the web client...

Right.

> i think my loops are wrong... maybe i can use IO to handle sockets?

No idea what you mean by that.

Cheers

robert

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
