Results 1 to 4 of 4

Thread: Binding a port to 2 applications.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    107

    Binding a port to 2 applications.

    I have a third party application that is using a certain UDP port on my machine. I have built another VB6 app that is using data from the same port for its calculations.
    I have no problem retrieving the data while the third party application is closed, but when it is running, my app cannot retrieve the data, since it tells me the address is already in use.

    Is there a way to share the port between the two applications? I cannot turn off either application, since I need them to run together. Any possibility?

    Thanks

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Binding a port to 2 applications.

    No.

    The only way would be to monitor the packets being received on that UDP port via port monitoring/packet sniffing.

    Something like this:
    http://www.pscode.com/vb/scripts/Sho...46567&lngWId=1

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Binding a port to 2 applications.

    The SO_REUSEADDR socket option allows a socket to forcibly bind to a port in use by another socket. The second socket calls setsockopt with the optname parameter set to SO_REUSEADDR and the optval parameter set to a boolean value of TRUE before calling bind on the same port as the original socket. Once the second socket has successfully bound, the behavior for all sockets bound to that port is indeterminate. For example, if all of the sockets on the same port provide TCP service, any incoming TCP connection requests over the port cannot be guaranteed to be handled by the correct socket — the behavior is non-deterministic. A malicious program can use SO_REUSEADDR to forcibly bind sockets already in use for standard network protocol services in order to deny access to those service. No special privileges are required to use this option.

    The exception to this non-deterministic behavior is multicast sockets. If two sockets are bound to the same interface and port and are members of the same multicast group, data will be delivered to both sockets, rather than an arbitrarily chosen one.
    Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE

    Basically this really isn't practical for your application.

    This is why for Windows LAN applications TCP and UDP are poor choices. Better choices might include Named Pipes and Mailslots, where you are not limited to the "tiny" address space of 64K port numbers. Sadly Microsoft never provided a component like the Winsock control for these Windows Networking equivalents of TCP and UDP, and so very few VB programmers use them.

    Your real "fix" here is to choose another port number for your VB application if possible.

  4. #4
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Binding a port to 2 applications.

    Why don't you just sniff the raw packets like DigiRev said.

    This project shows how to do it.
    http://www.pscode.com/vb/scripts/Sho...46567&lngWId=1

    You could tweak it quite easily to only sniff packets from UDP on a single port.
    Chris

Posting Permissions

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



Click Here to Expand Forum to Full Width