Your question is really only about elementary networking.
Edit Check out this most valued internet resource on network programming (basics to advanced):
- What is a socket? from Beej's network programming guide
A socket is a connection. A server is listening on a /port/ (TCP or UDP. Assuming TCP for the rest, since you're doing CGI).
Clients connect to the port and the server accept
s the connection, resulting in a socket (bidirectional stream, so to speak). The client now (usually) send
s and the server receive
s the request. Then the server send
s the response. (The connection may be closed, or kept alive depending on the protocol/preferences).
Specific answers:
query("localhost", "http");
would end up connecting to port 80 on most systems.
Of course you can also just specify the port number there:
query("localhost", "8080");
Choose the port number that the server bound it's listener to.