Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Broadcasting presence on a network

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a desktop application I may be developing I am wanting to embed a very simple P2P messenging system. That is to say, I don't want to use a server to transmit the messages. So I need a way to simply broadcast an "I am here" signal on a specified port and for all the other clients to be listening for that message on said port. So for an example;

Beth runs the application. She sends a signal saying she is here. No one else is running the app, so it just gets dropped. John then runs the app and sends the "I am here" signal. Beth's client picks up that signal and says, "Ok, John is here with xxx.xxx.xxx.xxx IP address. I'll send him a signal so he knows I am here too." John recieves it so John and Beth can now communicate through the application P2P.

Can someone guide me in the right direction. I really haven't done much socket programming. I have written a simple client server model like I spoke of so I am familiar with the API. But I just don't know what I need to do what I want. Thanks.

BTW - This is not a file sharing application or anything like that. I just need a non Server/Client model chat system. And this will all be intranet.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The most important thing is that you need to use UDP (i.e., DatagramSockets, not Sockets and ServerSockets).

There's a nice example of multicasting which would work fine on a LAN in Sun's tutorial, here.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ernest. I think I've seen that example before, just didn't read it much because I was looking at Sockets and ServerSockets at the time. I'll check it out.

Thanks.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thus you should find out if your Intranet supports multicasting.

Alternatively you could use io/nio and a loop for unicast datagrams.

I have written a testing code that receives files and user text messages. FileRX2 uses a single thread, a selector and Datagram/SocketChannels.
 
Evildoers! Eat my justice! And this tiny ad's justice too!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic