Client server communication with Winsock


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Client server communication with Winsock

Hybrid View

  1. #1
    Calderara Serge Guest

    Client server communication with Winsock


    Dear all,

    I am building a client server application using Winsock control.
    Based on that I have the following code part on server side which try to
    connect to the first based port and if not scan to the next free on on a
    range of 10:

    For iPortNumber = ServerInfo.ListenPort To ServerInfo.ListenPort + 10
    DoEvents
    tcp.LocalPort = iPortNumber
    On Error Resume Next
    tcp.Listen ' If we get an error, the port is busy.
    If Err.Number = 10048 Then ' port is busy
    Else
    ServerInfo.ListenPort = iPortNumber
    ServerInfo.bRunning = True
    Exit Function
    End If

    tcp.Close
    Next iPortNumber

    What happen next is that the client side application need to know what is
    the communication port that has been selected by the server.

    Is there a way that the server informed about the client about that port
    number ?

    For the client side, it used the based port number but as the server has
    notify that it was used then the client point to the wrong port tio initiate
    a communication.

    Thansk for your help
    Regards

    CALDERARA Serge
    Maillefer S:A
    Share on Google+

  2. #2
    Matt Guest

    Re: Client server communication with Winsock


    with the messenger I'm making, I use port 1169 for all the connections. I
    made an aray of winsock controls. when a connection is requested, I accept
    it, then make the next control listen. then I have an integer aray to keep
    track of what controls are being used. 0 for open, 1 for listening, and 2
    for connected. when a connection is closed, it checks to make sure there
    is a control listening.

    Matthew Kemmerer
    Mattsoft.net

    "Calderara Serge" <serge.calderara@maillefer.net> wrote:
    >
    >Dear all,
    >
    >I am building a client server application using Winsock control.
    >Based on that I have the following code part on server side which try to
    >connect to the first based port and if not scan to the next free on on a
    >range of 10:
    >
    >For iPortNumber = ServerInfo.ListenPort To ServerInfo.ListenPort + 10
    > DoEvents
    > tcp.LocalPort = iPortNumber
    > On Error Resume Next
    > tcp.Listen ' If we get an error, the port is busy.
    > If Err.Number = 10048 Then ' port is busy
    > Else
    > ServerInfo.ListenPort = iPortNumber
    > ServerInfo.bRunning = True
    > Exit Function
    > End If
    >
    > tcp.Close
    >Next iPortNumber
    >
    >What happen next is that the client side application need to know what is
    >the communication port that has been selected by the server.
    >
    >Is there a way that the server informed about the client about that port
    >number ?
    >
    >For the client side, it used the based port number but as the server has
    >notify that it was used then the client point to the wrong port tio initiate
    >a communication.
    >
    >Thansk for your help
    >Regards
    >
    >CALDERARA Serge
    >Maillefer S:A


    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center