TCP/IP software multiplexer

Posted on 2012-09-08
Last Modified: 2012-09-30

I need to build what I call a multiplexer. The purpose is to be able to get multiple input sockets directed through a single output socket. My strategy is to do the following.
On demand I establish a new input socket in an array, make a connection to the output socket and send data through it. Now, I will be receiving data back on the output socket. Since there will be several input sockets, is there a way to identify the input socket who sent that data. Also, since I will receiving multiple returns on the output socket, is there a way to prevent possible data loss by receiving them at the same time.
I will be using VB6, but VB .NET could be used also.

Question by:lxfdirs
    LVL 17

    Expert Comment

    I don't think you can 'hide' any marking in the IP or TCP header you send out, so unless you can work with the contents of the TCP segment, I don't think it's easily possible.
    LVL 55

    Assisted Solution

    by:Jaime Olivares
    yes, you can identify who sent the data at your multiplexer's listener, but once you forward it, you will lose that information. So the final application won't know who to send it back but to the multiplexer.
    To overcome this situation, you would have to wrap the original message along with the extra info of the sender.

    Author Comment

    Hi, guys:

    Appreciate your responses. I am taking them into consideration. Now, do you have some recommendation on the last part of the question --- Also, since I will receiving multiple returns on the output socket, is there a way to prevent possible data loss by receiving them at the same time.---. Will winsock as example, buffers the packets or handshakes with the sender to prevent data loss?

    LVL 55

    Expert Comment

    by:Jaime Olivares
    Are you using TCP or UDP? TCP shouldn't lose packets.
    A well known limitation is present in Windows desktop OSs. They will allow a short number of connections in parallel. For unlimited connections you need to use a server OS.

    Author Comment

    I am using TCP and application will run in Windows Server 2008.

    LVL 25

    Accepted Solution

    --> which answer corresponds to which input socket ?
    either the protocol which you are proxying supports multiplexing of commands, in which case you can rewrite the ids sent by the client and map the return ids to the proper client, or it does not in which case there is no way to do this and you have to queue the client queries

    --> data loss
    there should be no such problem over TCP and you'd rather focus on timeouts. setting tcp keep-alive client-side should help when lots of queries are queued. using an outgoing connection pool is obviously better than a single one.

    if you use a select or equivalent call or event programming, you will strongly minimise the risk since you never wait on a specific socket without listening to the others. during each of the program's loops, all the sockets that hold data yet to be read at the beginning of the loop will be read from during the loop, and the loop should be very fast if your proxy only acts as a multiplexer.

    reading "at the same time" is meaningless since reading from the socket means to read from a file descriptor, so the data comes in sequentially and not "at the same time"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
    Even if you have implemented a Mobile Device Management solution company wide, it is a good idea to make sure you are taking into account all of the major risks to your electronic protected health information (ePHI).
    Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
    After creating this article (, I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now