Hi guys,
As you know the Internet divided into private network and public network, the public IP which include to public network is accessible and private IP which include to private network is inaccessible due to Internet network.
So, I decided to use one of public servers have windows servers as an access point server.

I guess you wonder what I'm trying to do?

One of computers outside the world have server program which receives incoming clients and establish multi-connections with them. And this computer include to private network and you know that I can't access it from another private network because of NAT technology which resolves private IP to public IP. And I can't use port forwarding for that purpose.

So, I decided to use a server include to public network and is accessible and make it to route messages to that computer which is connected always with it.

In summary, I will explain it in following by supposing PC1 is my computer and PC2 is the server which routes messages and PC3 the server destination:

1- PC3 connect with PC2.
2- PC1 connect with PC2.
3- PC1 asks PC3 about the IP address and the port that PC3 connected with PC2.
4- PC3 establish PC1 with PC2 in new standalone connection with same ports that PC1 use it with PC2 and PC3 as well.

The following image shows what I want to do:

<img src="http://im39.gulfup.com/TcI9R.png" border="0"/>

My question is: "How can I make the server program establish connection between clients?"

Recommended Answers

All 9 Replies

Actually what you need is NAT. NAT actually performs the port forwarding for you, you would need to configure this using one of the following methods;
1. NAT Punching
2. UPnP
3. Manual Port Forwarding (which you said you can't do)

NAT punching is an old methodology that isn't very reliable in my opinion.
UPnP is almost universally supported by routers now and is probably the best way to go.

If you can't use UPnP, you can't achieve what you're asking with TCP, however, with UDP it might be possible. If you set up the connection to your server first with each machine (using TCPClient) you will be given a socket that the server will be replying to (on that connection), reply to the connected machine with that socket and then attempt to bind a UDPClient to it (this will most likely fail as socket in use exception but won't hurt to try) then also send the same port number to the other machine and attempt to make the connection. As UDP is a connectionless protocol, you should set up some kind of ACK to ensure you can actually communicate.

If the socket bind worked, you will now be able to transmit UDP to each machine and at this point it might be possible to close the TCP connection.

BIG NOTE MAKE SURE YOU READ: This is *completely theory. I have no idea whether it will work or not and will be a big programming outlay. It is important to note that what you asked for is not traditionally possible, however, this "hack" might just work. If it does not, then I'm afraid I don't know how to help

Thanx Ketsuekiame for your reply, but I don't want to do all of these, my inside work of my program must work like the way I said before. So, none of you said can apply to my program.
It must be some how to switch between connections of clients that attached to the server.
Is there any way to acheive this?

What you ask for is not possible.

So, you say there are no way to change the connection server-client to client-client!!!!

come on help me out, there must be a way to acheive this.

The application needs to release the ports before the new connection can be established. What you are describing is very similar to what a bit torrent tracker does, except it doesn't use specific ports, it just points the client to the other client and allows the OS to assign new ports once the connection is established. With the very defined restrictions in the first post, I agree i'm not sure it's possible.

No, it literally isn't possible. I've suggested three ways it can be done, but you've said you can't use those, therefore, what you ask for is impossible.

Please remember that a connection is not a physical entity, it's not like taking two wires and pushing them together. TCP doesn't work that way and UDP is connectionless.

What you think about yahoo?
Yahoo messanger was before (now yahoo depends only on server-client) make direct connections between clients in order to chat. And many hackers were use this to know the IP address of their vectims.
This operation similiar to what I want to do, isn't it?
What you say about that?

It operates in exactly the same way as my three suggestions above, most probably UDP Hole Punching.

Also, if you remember correctly, when Yahoo did this it was terrible are rarely worked properly. There was only a 100% success rate if both clients were directly visible to the internet (ie. Dialup) and there was no firewall in the way.

As in my first reply, there are three ways to do it. You've said you can't (or won't) use those. Without using any of those methodologies, what you suggest is not possible. End of discussion.

Alright, thanx Ketsuekiame for your replies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.