• Post Reply Bookmark Topic Watch Topic
  • New Topic

Broadcasting presence on a network  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!