Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Client to Client Chat Program

Options
  • 05-04-2007 5:59pm
    #1
    Registered Users Posts: 8,449 ✭✭✭


    Hey I'm thinking about doing a chat program like MSN Messenger or ICQ as a learning exercise for java networking.

    My problem is not to do with specific coding but theory.

    I want to be able to have a contact list where ye can see who of your contacts is online and I want people to have the ability of adding a contact by a username or number.

    The part I don't understand is, how do I get the IP of the other person in order to set up a connection or whatever. I don't want people to have to enter specific IP's either.

    Is the only solution a central server that is always on whose address all clients must connect to the first time they join? This would be for finding other users and would have the ips linked to names (the ips would be updated every time the client connects) Is that how MSN/ICQ do it?

    Thanks


Comments

  • Closed Accounts Posts: 4,368 ✭✭✭thelordofcheese


    I'm fairly certain thats how MSN does it (no idea about ICQ), i really can't see any other way of doing it without some sort of central server.


  • Registered Users Posts: 8,449 ✭✭✭Call Me Jimmy


    Yeah thanks, I'm just not at all experienced with networking so I wasn't sure


  • Registered Users Posts: 8,449 ✭✭✭Call Me Jimmy


    Does anyone know how to get a face ip in java? I'm only able to get the local address (192.168.1.*) etc. I have done searches and found nothing of any use.


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Does anyone know how to get a face ip in java? I'm only able to get the local address (192.168.1.*) etc. I have done searches and found nothing of any use.
    There are only 2 methods that i know of to automatically determine your external IP.

    1) Attempt to connect to a uPnP enabled router on your local network and ask it what it's external IP address is.

    2) Screen scrape a site like www.whatismyip.com. You should be able to write a dirt simple regex to parse the IP address out really easily. The pattern is "number, dot, number dot, number, dot, number". Really easy to do ;)

    Edit:
    3) If you are writing a client/server app and are in control of the protocol, you could define a message that the server sends to the client that includes the clients external IP address. It's easy for the server to detect the clients external IP as it can be read from the socket. So just send that info back.


  • Registered Users Posts: 8,449 ✭✭✭Call Me Jimmy


    3) If you are writing a client/server app and are in control of the protocol, you could define a message that the server sends to the client that includes the clients external IP address. It's easy for the server to detect the clients external IP as it can be read from the socket. So just send that info back.

    Thanks very much for yer response but is there a high level way of doing this in java? I can't find anything online about it if there is.


  • Advertisement
  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Your client-server application will obviously have a message passing system. So, one of your messages can be an "ExternalPort" message which your server will send to the client.

    The question is do you want to get low-down with sockets, or use something easier? I don't really know what java offers, but i'd say you won't have to get down and dirty with sockets.

    There is no higher level way to do what your describing. You have to design the message passing yourself, you have to design the protocol yourself, along with the messages.


  • Closed Accounts Posts: 97 ✭✭koloughlin


    You could try using the STUN protocol to get your external IP. STUN (see here http://en.wikipedia.org/wiki/STUN) is designed for voice over IP applications where NAT is always an issue.

    In any case if you can find some java libraries that have an implementation of a STUN client you can use a STUN server like stun.xten.com to get your external IP.

    One of the problems you'll face with a pure client to client solution is that you'll have to have users set up port-forwarding on their routers or traffic will be filtered out. If you have an external server piece to act as a middleman you can work around this, and this is how aim, msn, yahoo, googletalk etc. work. They can either just talk through the server on the client-server connections or a more complicated system can be used to enable direct peer-to-peer. See here http://code.google.com/apis/talk/libjingle/libjingle_applications.html for a diagram on how googletalk voice is set up to be peer to peer.

    Just had another thought.... I went through this book http://www.oreilly.com/catalog/hfjava2/ last year and they had an example of a simple im client in there. It doesn't handle NAT, but it might give you some ideas. Look in this jar file for the client and server pieces http://www.wickedlysmart.com/HeadFirst/HeadFirstJava/code/codeKitchensTiger.jar


  • Registered Users Posts: 8,449 ✭✭✭Call Me Jimmy


    Thanks for the replies, I'll look into some of that stuff today. It was just that the java InetAddress class, didn't seem to have a method for getting the face ip. It has getLocalHost() but this only returns the local ip on the network.


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Thanks for the replies, I'll look into some of that stuff today. It was just that the java InetAddress class, didn't seem to have a method for getting the face ip. It has getLocalHost() but this only returns the local ip on the network.
    Which is to be expected as if you are not connected *directly* to the internet, there is no way to automatically detect the external IP. You have to use some external source, whether it's using uPnP to query a uPnP compatible router, screen scraping a website, using a stun server (probably more trouble than its worth for you) or just pinging back the external IP from a central server.


Advertisement