-
using the internet
hello everyone,
I am starting up a new project which is a little complicated. At the moment i am looking at demo code but my software requires the use of many ports as it is a bit of a server,
here is the beginning of the code i am using:
Code:
int recv;
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any,
14800);
Socket newsock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
newsock.Bind(ipep);
newsock.Listen(20);
Console.WriteLine("Listening on ports 14800");
Socket client = newsock.Accept();
IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint;
Console.WriteLine("Connected with {0} at port {1}",
clientep.Address, clientep.Port);
In this we see a random port is used after the program connects, i however do not wish for this to happen. i have one main port and i wan't to keep it that way.I guess it is something to do with binding but not sure,
After this the port is closed and a new port with a higher number is opened(i'll do this later on though)
Thanks for the help,
Dave
-
Re: using the internet
Er, why don't you want that? The usual model is as follows (note to others: this is not my area of expertise, please correct me if this is inaccurate):
You bind a port as a listening port. When connections come in, you accept them which creates a new socket on a random port to handle communication with the computer that just connected. You then (if more connections are desired) set the original listener socket back into listen mode to accept another connection.
It shouldn't matter which port number you are using to handle communications once a connection has been established.
-
Re: using the internet
Or you could write this with WCF using the Tcp protocol and be done with it.