I have installed a streaming server "Lighttpd" (light-tpd) which runs on port 81.
I have a C program that listens to http requests on port 80 using a server socket created by socket api.
I want that as soon as I get a request on the port 80 from a client I forward that to the streaming server and the remaining conversation takes place b/w the Streaming Server and client & they bypass my C program completely.
The problem is client would be expecting msgs from socket at port 80 (i.e from the socket of my C program) since it had sent request to port 80 only rather than from the Streaming server which gives service on port 81.
can anyone help me out on this issue of bypassing the socket on port 80 for replying to the client.
Solution I think: my program can be a middle man...It will forward the request to port 81 of streaming server and when it get replies from there it forwards them to the client...but bypassing would be efficient and I don't know how to do that. Please help me out.
Thanks in advance
Why put your C program in front? Lighttpd is designed to act as a frontend proxy (among other uses), so you can put lighttpd in front and use its mod_proxy_core to pass requests to your C program. You can use X-Rewrite and/or X-Sendfile to pass requests back to Lighttpd after doing some processing inside your application.
I have recently implemented a similar technique where a single program accepts a TCP connection and then 'passes' that connection to another component and plays no further part in the socket conversation. It uses the technique of passing the file descriptor of the accepted socket over a UNIX socket to the server component which effectively does an inter-process dup() of the fd.
See here and here.
This works for me as I have control of both ends of the UNIX socket on the server-side, but to work for you, you'd need:
A UNIX socket between your dispatching component and server components.
Full control of the server component.
You might need to hack away at the lighttpd source code...
Sorry, not really an proper answer...
Related
I've been trying to create a proxy server to analyze TCP packages sent between my computer and a game server.
Now I know that you can do this kind of stuff with Wireshark, but I want to understand the logic of it and how the connections are made.
My main question is that I don't know where to start from. I have the server IP and port from Process Explorer and have the basic socket programming knowledge in python, but as I said, I don't know what to code.
Am I supposed to write a socket that hijacks the incoming TCP connection and forward it to my localhost? but then how would my client send data to server?
As you can see, I'm a bit lost, and I would be very happy if someone could put me in a correct path (what should I research?).
Thank you in advance.
I think there is a useful tools can help you: iptables and netfilter. Using this, you can hijacks the incoming TCP connection and forward it to your localhost easily.
I need to write my first socket program involving TCP connections. In the program I have created there is a client and server, both of which are the machine I am coding on.However,it requires that I pass the port number as a command line argument. How do I accomplish this?
The answer is simple : Make sure your server and your client agree on the port to use. As long as the port is available and can be used, set up the connected so that the client and server use that same port.
Here's a link that explain the different ranges available for TCP and UDP ports.
As an exemple, the port 3074 is used by microsoft for its Xbox live service. Making an application using this port might interfere with the service.
The port used will be defined either in a configuration file or hard-coded in the source code of both the server and the client. You should easily be able to find it with a quick look at the code or the directory which contains the application.
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
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.
If you telnet to the ip address 192.43.244.18 port 13, you'll get the current time.
well, if I'm not wrong, this is simply a server socket. But there's one thing strange: how's this socket always listening?
If I take a PHP page and program sockets in there, I still have to request for the page first in order to activate the server socket, but this one isn't associated with any pages, and even if a make a perl script, I still have to request for that in order to run the server socket!
My question is: how can I make such a thing - an always listening socket - on a webhost (any language will do)?
You can run the process that's listening on the socket as a daemon (Linux) or service (Windows), or just a regular program really (although that's less elegant).
A simple place to begin would be http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html which teaches you how to make a simple serversocket in Java that listens for a connection on a specific port. The program created will have to be run at all times to be able to accept the connections.
I have 2 sip clients on the same computer.
Both of them is registering to a server that is running on port 5060.
For the first client the UDP is on port 5060 and for the other is 5061. When I come from one client to another, after the ringing part i receive the error:
only one usage of each socket address is normally permited.
Got any ideas why I got this error?
Your server and client are both trying to use port 5060, hence the error message. Change the first client to use 5062 or something else.
Also, 5061 is normally used for secured SIP (normal listening port + 1 in the proxy/server). Do not use it for the second client.
It means you're clients are both trying to claim the same socket for the communication channel, or the server is trying to reclaim the socket given to client A, to reuse it for client B.
The software handeling the socket, should be smart enough to rely on the OS to assign port numbers instead of hardcoding the port numbers in the code, this is a 100% guarantee for socket issues.