CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011

    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:

    int recv;
                byte[] data = new byte[1024];
                IPEndPoint ipep = new IPEndPoint(IPAddress.Any,
                Socket newsock = new Socket(AddressFamily.InterNetwork,
                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,

    Last edited by micr0man; July 16th, 2011 at 10:13 AM.

  2. #2
    Join Date
    Feb 2011
    United States

    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.
    Best Regards,

    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: using the internet

    Or you could write this with WCF using the Tcp protocol and be done with it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

By using this site, you agree to the Privacy Policy