Eagor's Forums » CEN6520 - Project 2 » What port is your server using?
Author Topic: What port is your server using?
Steven Eagen
Posts: 14
  Date Posted: 2005-01-30 22:38

David Mauk asked:

What port are we going to use for our routers? (I guess it really does not matter as long as everyone makes an easy way to change their port(s)(what I am really trying to say is what port is everyone else going to use during personal testing so that we do not accidentally contact each others routers until we are ready to).
 
Steven Eagen
Posts: 14
Date Posted: 2005-01-31 00:01

I will be using port 2801 to test on. We need to decide on a port to use when we all test together.
jesse_sweetland
Posts: 14
Date Posted: 2005-01-31 07:08

Lets make port# configurable via the command line. This will help greatly when testing clients and routers on the same machine.
jesse_sweetland
Posts: 14
Date Posted: 2005-02-08 19:23

Just thought of something. If the client and the router are going to be operating on the same machine, then they will need to have different ports. Recommend router has *at least* two command line parameters: router-router port, and client port (I have 3: rPort, cPort, and rtFilePath). Note that the port is not needed for client-router communication, but is needed for router-client communication. Further recommend that all routers use the same port (for simplicity). Since it is a command-line argument this should not be a problem. Also: client will need to have at least two command-line parameters: : its port and the router-router port (again, I have three; the same as for the router).

Comments?
David Mauk
Posts: 17
Date Posted: 2005-02-08 20:13

What you say is true that is what I had assumed sorry not to have posted my findings earlyier.

That should work very well
David Mauk
Posts: 17
Date Posted: 2005-02-08 22:46

When the client sends to the router since they are on the same machine, the client need to send from port x and the router need to receive on port y. So I need to bind my router's socket to port x and bind my client's socket to port y?

If so then the router will send and receive on port x and the client will send and receive on port y.

Hmm, I think that works (at least it does in my mind).
jesse_sweetland
Posts: 14
Date Posted: 2005-02-09 18:34

What should actually happen is this:

1. Client creates listener thread
1.A. Listener thread opens socket on clientPort and calls recvfrom in a loop
1.B. When packet received, save/display contents

2. Client enters user input loop
2.A. User selects option
2.B. Client opens a socket on routerPort (same IP)
2.C. Client sends packet
2.D. Client closes socket (routerPort)
2.E. Repeat if !exit

3. Router opens a socket on routerPort and calls recvfrom in a loop
3.A. When packet received, spawn a new thread to handle it and listen for next packet on routerPort (same socket)
3.B. If sending to a router (different machine), open a new socket to next IP on routerPort, sendto, and close socket
3.C. If sending to a client (same machine), open a new socket at the same IP on clientPort, sendto, and close socket

What that boils down to is this: clientPort and routerPort are the ports that the client and router (respectively) listen on. The ports used to send are unknown (we don't care what they are).
Mengshu Chen
Posts: 2
Date Posted: 2005-02-09 22:40

According to Jesse's solution, how are we supposed to change the two working patterns of the client? I mean, when should the client send and when should it hear on the message from the router?
David Mauk
Posts: 17
Date Posted: 2005-02-10 13:44

One solution is to use a select().

The select allows you to specify a set of "descriptors" that will be watched for actions to be performed on them.

Then when something happens select() returns the descriptor's # and you can use it in some kind of comparison.

When you find a match to one of your "descriptors", you will then know what to do.

Keep in mind this is just one of possibly many solutions.

For more information on select() and related topics use this URL: http://www.ecst.csuchico.edu/~beej/guide/net/html/advanced.html

The surrounding pages also have information that might be usefull.