Forum Moderators: open

Message Too Old, No Replies

Run a program as a "server"

Create a program that listens to port 80

         

digi_mind

11:33 am on Nov 4, 2003 (gmt 0)

10+ Year Member



I am trying to create a progam that listens to port 80, but I get an error message every time I start it. The message is due to the fact that another program is already listening to that port.

How I can disable other programs in windows, so they won't be listening to port 80. I know that TCP is listening to that port, so:

How can I disable it? or better
How can I use this program, already listening to port 80, to connect my server to this TCP?

killroy

11:38 am on Nov 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TCP is not a program. It's a protocol used for communication.

Port 80 is one of over 65000 ports available for TCP communications, and is traditionally reserved for HTTP connections.

If port 80 is taken, that most likely means you have a webserver running on your computer. Perhaps Apache or IIs or the PWS Personal version.

Get a good TaskManager (like TaskInfo) and identify them on the list. Kill all the server tasks and se if your program can then bind to port 80. Low levelr socket programming is somewhat complex, and I suggest you read up all you can find on IP, TCP, HTTP and socket programming. It can take quite a bit of learning to get used to all the details.

If you want to get rid of your local web server for good, type "services.msc" in a command window, and change all webservers to "manual".

Best of luck,

SN

killroy

11:42 am on Nov 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, sorry, just noticed this is the ASP forum. If you want to write this in ASP, you CANNOT listen to port 80, as port 80 would be used by the webserver executing your ASP script. Of course you cannot kill that process while it'S running your script. You'll have to use a different port for your script.

If you could explain in a little more detail what you are trying a achieve, teh ASP gurus around could help you more I'm sure. I've only done low level socket programming, and no ASP.

SN

digi_mind

11:48 am on Nov 4, 2003 (gmt 0)

10+ Year Member



This is what I am trying to do:

I already make a program that allows many users to chat with each other.

The "server" rund in port 6180, but this only works in my internal network. If the server was behind a firewall, then it wouldn't work.

That is why I want to start my program listening to port 80, so no firewall will intervine in the process.

TCP is listening to port 80, but I don'e have any web server running at this moment. TCP start by default.

If I don't disable TCP, can I some how use it for my applicaiton?

digi_mind

12:01 pm on Nov 4, 2003 (gmt 0)

10+ Year Member



Well, Apache was the one. It was starting automatically in my computer. Now I just whut it down and I can listen to port 80 with my server.

Now I have this:

My program is running in two different computers, one acts as a "server" and the other one as a "client". When the "client" says "hello", then the "server" gets this information and here is the deal:

Computer one which is the "server", after getting "hello" becomes a "client" and syas "I am here".

Computer two, which was a "client", becomes a "server", so it can listen and get "I am here".

Is there a better way to create an application, so the computer doesn't have to be client and server at the same time?

killroy

12:09 pm on Nov 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You only need one server at a time, TCP connections are two-way. Again, rmemeber TCP is a protocol, NOT a program.

You bind to a listen port, in your case port 80. When the connection is established, you are actually talking to one of the freely assignable ports above 1024.

So it goes like this:

C:port 43000 -> S:port 80 : Connect
S:port 80 -> C:port 43000 : let's talk on port 54000
C:port 43000 -> S:port 54000 : Hello
S:port 54000 -> C:port 43000 : Got your hello

Now the assigning of the new port is random and automatic. depending on your language, after reciving the first connection on your lsiten port, you have some form of connection object, which has the new port assigned.

firewalls are no issue fomr here on onwards, because they only block NEW connections. Once the connection is established through port 80, you can talk on the new ports.

But it would be much easier to open a new port in the firewall. Because if hte computer does NOT run a webserver on port 80, then cahnces are port 80 woiuld be closed in the firewall as well.

SN

digi_mind

12:23 pm on Nov 4, 2003 (gmt 0)

10+ Year Member



Let me make sure I understood your example:

C:port 43000 -> S:port 80 : Connect
S:port 80 -> C:port 43000 : let's talk on port 54000
C:port 43000 -> S:port 54000 : Hello
S:port 54000 -> C:port 43000 : Got your hello

C and S are both client and server at the same time, is that right?

digi_mind

12:27 pm on Nov 4, 2003 (gmt 0)

10+ Year Member



I did something like this:

I create a program, the server listens to port 80. Then I should change the port number, so the server can listen to port 5000. When I try to change the port number, it crashes. I get a message telling me that I can not change the port number when the server is active.

If I deactivate the server, then I will have to start the process again, it will be like starting my program with my server listening to port 5000.

How can I change the port that the server is listening and keep the connection?

digi_mind

12:33 pm on Nov 4, 2003 (gmt 0)

10+ Year Member



I am confused now, I just start thinking about explorer.

Internet Explorer is a client, it send data to port 80, and it gets an answer from throught that port.

When it send the request, it is a client. When it gets back the web site, it is :

- A server listening to port 80?
- It is a client that is able to listen to incomming data?

killroy

12:46 pm on Nov 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The port changehappens automatically.

use NET or a packet sniffer to check on your internet explorer connections, and you will notice that in fact IE does NOT get the response back on port 80. Otherwise, only one client could only ever connect to awebservcer at a time, which is obviously not true.

SN

digi_mind

12:58 pm on Nov 4, 2003 (gmt 0)

10+ Year Member



Then probably most of the programs, as explorer, skype and so on are a client and a server at the same time.

Explorer is a client and a server?

If the computer "A" send something to computer "B", then computer "A" can not get any answer babk, unless "A" is also a server.

If computer "A" send something to "B", then computer "A" is a client, how can computer "A" get something from "B", if "A" is behind a firewall?

Once "A" sent data to "B", "B" can send something to any other port above 1024 and "A" will get it without any firewall problem, becuase "A" already opened a connection with "B"?

Could you please tell me if those things I wrote are right?

Dreamquick

1:33 pm on Nov 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Explorer is a client and a server?

No, internet explorer is only a client. A server is something that sits and waits until it's asked for something but doesn't actually issue requests. A client on the other hand doesn't actually sit and wait, but instead just issues requests.

On the other hand things like P2P applications are both clients and servers at the same time because they issue their own requests (client) and deal with incoming requests that they listen for (server).

If the computer "A" send something to computer "B", then computer "A" can not get any answer babk, unless "A" is also a server.

No, "A" (client) sends something to "B" (server) and then gets a response back within that same connection - this is exactly how a website works on a simple level with one client (my browser) and one server (e.g. apache or IIS)

If computer "A" send something to "B", then computer "A" is a client, how can computer "A" get something from "B", if "A" is behind a firewall?

The connection is established by "A" from inside the firewall, and the response from "B" is returned in this same connection therefore there are no firewall problems since no new connections are being opened.

If "B" (external server) needed connect to "A" (client) without "A" establishing the connection then you would have firewall problems since that would be viewed as unprompted.

Once "A" sent data to "B", "B" can send something to any other port above 1024 and "A" will get it without any firewall problem, becuase "A" already opened a connection with "B"?

Port allocation is normally handled for you so you don't need to worry about exactly which port you are using once the initial connection is established.

In the example your connection was being handled on port 54000 on the server, which is fine ... but if you try to send data on a second connection to server port 54001 then your connection will be refused.

Equally it's not true to say that just because there is already one "trusted" connection from "A" to "B" that "B" can now connect directly to "A" on another connection and bypass the firewall.

Could you please tell me if those things I wrote are right?

They are heading in the right direction but if we understood you correctly you aren't quite understanding the idea yet. You might want to try doing more background research via Google since it has a lot of technical material indexed.

- Tony

killroy

2:29 pm on Nov 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TCP connections (and remember TCP is NOT a program) are two way. So a client can talk to a server and a server to a client through the same orgiginal connection.

I urge you to read up on hte basics of TCP. It's quite complex, and would be hard to explain staisfactorily in a thread here. Perhaps somebody can suggest a good tutorial to TCP programming.

SN

digi_mind

4:40 pm on Nov 4, 2003 (gmt 0)

10+ Year Member



Perhaps someone has some C++ source code, so I can have a llok at it.

Te souce code should be something really simple, a client sends something a another computer, and this last one replies with a message.

If I run the program, then I will get a better understanding of it. My application is created in Broland C++, so the client-server connection and so on is handled by pre-built Borland functions.

victor

5:07 pm on Nov 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are not averse to trying a less-well known language, you may only be 30 lines of code away from a working system.

Take a look at this example, and the other proxy server etc examples on the same site.

[rebol.org...]

digi_mind

5:26 pm on Nov 4, 2003 (gmt 0)

10+ Year Member



Thanks for the link, but I have never seen that language before, though I will try to compile and run it.

I just did something in Borland:

I have computer "A" which is the client and is behind a firewall.

Computer "B" is the server, and it is not behind a firewall. "B" is listening to port 6180.

Now, "A" starts and gets connected to "B", and "B" repplyes hello.

"A" is behind a firewall, but It got the message anyways, because it was the one opening a conecction.

This is bettween "A" and "B". How about if computer "C" enters the picture, and "C" is also a server, but it is "A" and "C" who want to talk to each other and they are both behind a firewall? The only way to get connected will be through "B". HOW?

plumsauce

10:02 pm on Nov 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




search for "winsock faq", you will find
tutorials, sample code, and of course, the faq.

after you have digested that, you will need to
figure out multi-threading, and particular to
win32, async i/o.

then, once you have it running as a console app,
you will need to figure out how to modify it
to run as a service.