0

I'm trying everything to NAT traversal to make a HTTP(or others) server be accessible from internet. this is the previous question but with no luck. HTTP Server behind NATs

So I'm trying to do the following

IE <--> agentC <---------NAT/Internet/.....----------->agentS<------->Apache Server

the scenario might be...

1.User input address in IE like "localhost:9999" (agentC)

2.agentC connect with agentS with Stun/TURN/ICE

3.agentS relay data to Apache Server and then reply to client.

I also refer to the following: Is it possible to 'relay' a socket?

but the problem is:

1.the connection between agentC to agentS might be UDP, however the Http is on TCP, is it possible to "relay socket or packet"

2.I'm coding test code of agentS<---->Apache part,

((pp = popen("echo -e \"GET / HTTP/1.0\\n\\n\\n\"| nc localhost 80", "r")) == NULL)
.........

But the out put always "400 Bad Request". (while type "echo -e "GET / HTTP/1.0\n\n\n"| nc localhost 80" in console will be successful)

3.I will modify a simple console chatroom to be agentS and agentC, is it possible to carry the http data (like pic,download...etc)?

Thank you for your patience

Community
  • 1
  • 1
Smith.Lai
  • 142
  • 1
  • 8

1 Answers1

0

You don't really relay the socket, instead you relay the data. For example, "agentS" in your example opens a listening socket where it accepts connections from "agentC". When it gets a new connection from "agentC" then "agentS" connects to the web-server and enters a loop where where all it reads from either connection ("agentC" or web server) is sent to the other connection.

Since the two connections are independent it doesn't matter if one is TCP and the other UDP.

Also, if you need to do some processing on the data in "agentS" it's easy, as you actually have the data. The protocol between "agentC" and "agentS" doesn't even have to be HTTP, it can be whatever you want, as the programs can do protocol translation.

As a side note, when sending data to a web-server you end the lines with "\r\n", and the header is terminated by a single "\r\n" on its own line. So you only need to send "\r\n\r\n" after the GET request.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Oh my god,thanks for your reply. I was trying to build one from a simple chatroom code but encountered many trouble.... I found a cool resource [http://code.google.com/p/udptunnel/], I might study how it works and see if I could replace the UDP connections with STUN. – Smith.Lai Aug 01 '12 at 05:57