LAN chat program

Discussion in 'Software' started by BrokenArrows, Nov 27, 2005.

  1. BrokenArrows

    BrokenArrows Sergeant

    I am currently thinking about developing a lan chat software.

    One of the features that i intend to implement is the ability for a user to set up a chat room and for everyone else using the software to be able to access this server.

    I was thinking about how the users would be able to find the servers.

    I was thinking about the way that Multiplayer games find servers on the LAN so i ran a port scan on Call of Duty when it was trying to find server.
    The way Call of Duty works is it sends a UDP packet to IP 255.255.255.255 from port 28960 to port 28960,28961,28961,28961.

    All server then reply to ths request.

    How would i implement this in a chat program to return all the servers that are running on the LAN. I intend to use JAVA.
     
  2. goldfish

    goldfish Lt. Sushi.DC

    I'd suggest you use UDP broadcast. Have a server respond to "probe" packets, sent out by clients aiming to enumerate available rooms. You only need to have it use one port, since its a pretty simple implementation.

    The UDP packet will be recieved by all clients on the network, and they simply reply with another UDP response with the appropriate info.

    Then, when you're actively joining a chatroom, have it do a TCP connect to the server hosting the connection (using information obtained using the UDP probe).

    Hope that helps!
     
  3. BrokenArrows

    BrokenArrows Sergeant

    Thanks that helps alot.
     
  4. QuickSilver

    QuickSilver Corporal

    I don't have any experience in developing this kind of thing, but I don't think it would be too difficult with Java because you can get the nitty gritty network stuff done and then cobble a front end on...

    So from what I recall, within Java, you want to be using sockets for communication... to start off with, on your LAN write some simple programs to send data from one machine to another with hardcoded IP addresses... I once wrote a very simple app to just send a message from one machine to another demonstrating client/server models and it was about an hours work with Java so I think you'll be able to get something fairly straight forwards going in no time at all...

    Right now I'd think about the design of the software you want... This program is going to end up sending messages over a protocol to a server. You are then going to have a server program sending messages based on this to each client...
    So you're going to need some sort of message structure and part of this should solve your problem.
    One option is just to have each client app configurable as to what it thinks the server is... So the user just specifies a server IP address and a port.
    A hackier option could be that a 'broadcast' message is sent across a LAN subnet essentially asking each machine 'Are you the server?'... Each machine on the subnet could then respond saying 'Yes' or 'No'. This has its up's and down's...
    Pro's
    - No hardcoded servers
    - no messy configuration settings

    Con's
    - Unnecessary traffic on the network
    - what if more than one machine claims to be the server
    - limited by subnet definition (as specified on client-side OS)


    Personally I would go for a configurable setting... :)

    As for what you observed on the Call of Duty exercise you carried out - weird... A UDP packet is not guarunteed to reach its target - and whilst I don't have my IP book to hand, 255.255.255.255 is the highest numerical IPv4 address and its unlikely to be a valid IP address... Im sure it has a different use in the wacky world of IP... I just can't remember what... and I can't ping it :)

    Call of Duty is designed to run over the Internet, not just a LAN, so it will have some different behaviour in establishing multi-player games... Im fairly sure if you're just interested in having a LAN-scale chat app that you can do it a little tidier...
     
  5. goldfish

    goldfish Lt. Sushi.DC

    UDP broadcast isn't "hacky". Doing essentially a Ping Scan would be hacky, and would take an AGE.

    UDP packets, although not garunteed to get to their destination, do not have any particular destination. In an ideal network with zero collisions you send out a single UDP packet and ALL clients recieve. If they have the appropriate software running, they will respond. Sending out a TCP SYN packet for every single possible host on the network (which you'd have to guess at, might be Class C, B, A... who knows) would generate a LOT of needless traffic. A packet for each host.

    Using a probe packet is much more efficient in this situation. Bearing in mind that it is in a LAN, not a WAN, you can rely on UDP to an extent. If you go further than one router down the line though your UDP traffic starts to get filtered.

    A UDP packet aimed at 255.255.255.255 is a broadcast packet...
     
  6. BrokenArrows

    BrokenArrows Sergeant

    yes i already have written a chat app on on the command line where the ip and port are entered and the chat carries on from there.

    The 255.255..... ip address is a broadcast ip address. It sends the packet to all computers on the network. I think this might be my best option.

    I want more than one server to be available on the network. So for every computer that replies Yes i will add them to a list and the user will select what server to connect to.

    Now i just need to find out how to create the broadcast packet in JAVA.
     
  7. goldfish

    goldfish Lt. Sushi.DC

  8. BrokenArrows

    BrokenArrows Sergeant

    excellent thanks alot.
     
  9. QuickSilver

    QuickSilver Corporal

    Sweet.. I didn't realise thats what a UDP to 255.255.255.255 did... Definitely sounds like the way forwards :)
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds