I have been given a task

Programming, for all ages and all languages.
Post Reply
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

I have been given a task

Post by Zacariaz »

I have been given the that to write a simple chat program.
1. It will be console based
2. It wil establish a connectin between two computers, both hidden behind a private gateway. It connection wil not be server based if avoiable.
3. Percausions must be taken to assure privacy.

Now this all sound simple enough, and when my body asked if i could do it i said ya, no problem, however, after having spend the entire night investigating various protocols and stuff, im ready to take my words back. Allthough networking has never been my strong side, i didnt think i would have such a hard time figuring this out.

I would hate giving up on this, so if anyone is able to point me in the right direction, it would be greatly appresiated.

As allways i prefer any code in c++ or ofcourse nasm syntaxt ASM, but i doubt that will happen ;)

What i have done so far is reading whatever little i could find about the t.134/T.chat protocol, however as so little information seemingly is availible, i guess im on the wrong track.

Regards
Last edited by Zacariaz on Sat Jun 30, 2007 8:06 pm, edited 2 times in total.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post by Kevin McGuire »

Use UDP/IP.
Use a XOR encryption on the messages.
2. It wil establish a connectin between two computers, but hidden behind a private gateway.
Is it specified that you must use a connection oriented protocol?
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

sorry, i just added and corrected a little, i you care to read again, and thanks for the quick answer.

About the connection ariented protocol, im not quite sure what ou mean, the important part is that the comunication is direct and not relayed by a server.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post by Kevin McGuire »

TCP is a connection oriented protocol because a handshake must occur before transmitting data between the two computers. In contrast a UDP packet may be sent at any time between two computers, as long as one is listening for it.

UDP is light weight and supports sending broadcast packets, which are very useful for implementing a mechanism in the chat program for automatically detecting other participates whom have this program running.

They both however multiplex packets to the proper applications on the operating system by using ports.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

But what about the gateway thingy? i mean two computers need to comunicate directly, but cannot be addressed by the local ip alone due to a private gate way on both hands, i this a problem at all?
and what about dynamic ips?
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

The gateway is definitely a problem. Suppose the server is behind a router and the client is not. Now you have the private IP (the IP behind the router in the server's LAN). You will not be able to connect to that IP simply because it is an invalid and a private IP. I used to have the same problem with my chat program and I solved it using the Reverse Connection technique.

As its name implies, the connection should be reversed somehow that the computer behind the router will connect to the computer that is not behind the router. If both computers are behind routers then there is no way direct connections can be established unless the ports to/on which the client and the server work are directly routed outside the LAN and both the computers are given public and valid IP addresses. As long as they have private IPs (both), you will not be able to establish a connection.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

This response assumes by 'both hidden behind a private gateway' you mean that both clients run on computers that have IP addresses which are not visible or routeble to from the internet, e.g. they have private IP addresses but access the Internet through the use of NAT.

For chat programs you can get away with using UDP instead of TCP, and it is generally easier to set up. In windows, look at the Winsock API, in unix look at the socket type functions, e.g. connect, bind etc.

To successfully cross the router, you need some form of NAT traversal which will forward a port from the router to a specific IP address on the private network. E.g. you can set up your router (which has a public IP address) to accept packets on port 666 and forward those to IP address 192.168.0.34, which would in turn be running a client which is accepting packets on that port. Most routers allow you to do this manually via a web-based configuration scheme. You would need to choose a port number for your chat program, and then set up the router at both ends to forward the particular port. Then you would need to determine the public IP address of the opposite router to send packets to, possibly by use of a dynamic DNS service.

There is an automatic way to set up the port forwarding rules in a router called UPnP which is used by programs such as BitTorrent clients.

Regards,
John.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

I dont have access to the server, routers, firewall, etc. so that is out of the question. 2 questions remains.

1. what if i have both the public and the private ip, maybe even mac adresses and stuff, will it then still not be possible to establish a direct connection?
2. If the use of a server app to establish the connection, will it then be possible, when the connection is established, not to rely on the server?
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post by Kevin McGuire »

1. what if i have both the public and the private ip, maybe even mac adresses and stuff, will it then still not be possible to establish a direct connection?
ComputerA(192.168.1.34)->Router1(192.168.1.1<-NAT->45.87.23.2)->(INTERNET)->Router2(85.23.43.2<-NAT->192.168.1.1)->Computer(192.168.1.3)
You could have all the information including the MAC address of each computer. Unfortunately, the MAC address will be of zero use when transversing the internet. The packet will come from ComputerA and arrive at Router1. The Router1 will translate the packet by changing the source address to the external side's (internet side) address of 45.87.23.2. The packet will travel across the internet and arrive at Router2. The Router2 will drop the packet because it has no port open matching the destination port in the packet.

The only remedy is to use UPNP to open the port on Router2.
This situation will also have to work in reverse where Computer1 has to use UPNP to open the appropriate port on Router1.

Most modern routers for home usage have UPNP enabled by default specifically for this reason. You will have to do a search on UPNP. The router generally will broadcast using a UDP packet on a certain port that it has UPNP enabled.
2. If the use of a server app to establish the connection, will it then be possible, when the connection is established, not to rely on the server?
Once the server disappears or gets removed from your situation you will be left with the same problem above.

How To Get Around This Problem
Use a IRC server as a proxy. Just write a little front-end code code to establish a connection to irc.freenode.net, for instance. This would enable you to tunnel the connection through the IRC server. The IRC protocol is extremely simple and easy to work with.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

what i am hearing here is that it would probably be a whle lot easyer writing a php scripth or simular instad?

Anyway, thank you for the replys.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post by Kevin McGuire »

What operating system are you having to write this for?
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

Kevin McGuire wrote:What operating system are you having to write this for?
Windows xp, but in generel i try to make the code os independent.
Post Reply