How to send a packet to multiple recipients?

I'm writing a small chat program in java. What I have so far for the server, is this:
import java.io.*;
public class datagramServer {
     public static void main(String[] args) throws IOException {
          new datagramServerThread().start();
}datagramServerThread class:
import java.net.*;
import java.util.*;
import java.io.*;
public class datagramServerThread extends Thread {
    protected DatagramSocket socket = null;
    boolean listening = true;
    datagramProtocol DGP = new datagramProtocol();
    public datagramServerThread() throws IOException {
     this("datagramServerThread");
    public datagramServerThread(String name) throws IOException {
        super(name);
        socket = new DatagramSocket(4445);
    public void run() {
        while (listening) {
            try {
                byte[] buf = new byte[256];
                DatagramPacket packet = new DatagramPacket(buf, buf.length);
                socket.receive(packet);
                String processSendBack = new String(packet.getData());
                String sendBack = DGP.processInput(processSendBack);
                buf = sendBack.getBytes();
                InetAddress address = packet.getAddress();
                int port = packet.getPort();
                packet = new DatagramPacket(buf, buf.length, address, port);
                socket.send(packet);
            catch (IOException e) {
                e.printStackTrace();
        socket.close();
}And the datagramProtocol class:
import java.io.*;
import java.net.*;
public class datagramProtocol {
     String output;
     public String processInput(String toProcess) {
          output = toProcess;
          return output;
}Pretty simple, and it works great, if you just want to chat with yourself... ;)
The client is really simple, just sends and receives, nothing fancy.
What I want to know, is how would I send anything any client sends, to every other connected client?
btw, I was wondering if it's good coding practice to put everything into a seperate class like that. I probably could've put everything into one, but it's a little neater in seperate files.
Thanks,
Alex

Can a publish/subscribe sort of model be used in it's
place? Or how about just a listener model rather
than pushing each request? This way the clients just
register themselves and listeners and you merely
propogate an event. There would be no need to keep
track of each IP, etc.
Just thinking out loud here... :)Well, as I understand, on a publish/subscriber model, the publisher has to keep some sort of reference to the listener in order to send the events when they happen.
Keeping the sockets to the clients seems to me as good as a reference can be on a TCP/IP connection short of using RMI to do that, but if the client/server must be decoupled from the language what I sugested is a publish/subscriber model. The clients are the subscribers, they ad themselves as such upon connecting to the server, the server wich is the publisher store their reference as subscribers by keeping the socket where they agreed upon communicating.
When the publisher has a new message to be published it walks the list of references giving them the event, wich is the message posted.
Sure it could be done with events just notifying the arrival of new messages but it would just complicate the model beyond the need. For the client would have to wait for the event and them send a request asking for the actual message, in order to do such a system he would have to create a simple protocol of comunication between the client and the server.
May the code be with you.

Similar Messages

  • Oracle Obiee - Send Obiee reports to multiple recipients

    Hello All,
    Can anyone tell me how to send Obiee reports to multiple recipients?
    I have used the ibot of Oracle Obiee. And ibot is working fine for the Creator of the ibot but it is not able to send reports to other recipients.
    When i get mail from Oracle Delivers the To section is empty and bcc section contains the creator of the ibot.
    Please help me on this.
    Thanks & Regards,
    Jiten
    Edited by: Dr.Jiten Patel on Aug 16, 2012 5:14 AM
    Edited by: Dr.Jiten Patel on Aug 16, 2012 5:15 AM

    Again, this is the Application Express forum, not the OBIEE forum.

  • How to use Add_Delivery_Option to send an email to multiple recipients

    I have the following code before i submit a concurrent request:
    B_Delivery_Success := Fnd_Request.Add_Delivery_Option(
    'E',                    -- EMAIL
    'Enter subject', -- SUBJECT
    '[email protected]',          -- FROM
    '[email protected]'          -- TO
    ,NULL               -- CC
    which correctly sends an email with attachment. However i need to send the email to multiple recipients. How can you enter multiple names against the 'TO' parameter. I know that i can repeat this again and again with a different email address each time, however there must be away to use this code once with multiple addresses?
    Edited by: user974582 on 09-Oct-2012 01:23

    Not sure about the API but there are other ways to achieve it i.e. through alerts.. You can refer below
    Can Concurrent Request Notifications Work With A Group Email ID [ID 1096850.1]
    Cheers,
    ND

  • How to send one text to multiple numbers

    On iPhone 3GS , how do u send 1text to multiple numbers?

    The information below implies you must use MMS or iMessage (not SMS).
    [extracted from the iPhone User Guide for iOS 5]
    Sending messages to a group
    Group messaging lets you send a message to multiple recipients. Group messaging works with iMessage and MMS (not available in all areas).
    Send messages to a group: Tap the new message button, then enter multiple recipients.
    Note: With MMS, group messaging must also be turned on in Settings > Messages, and replies are sent only to you—they aren’t copied to the other people in the group.

  • HT5361 How can I forward mail to multiple recipients?  When I try to add an address, it replaces the previous address

    How can I forward mail to multiple recipients?  When I add an address, it replaces the previous address.

    Using the + button helped--should have been obvious, but I haven't been using it.  It works but seems very cumbersome to add one at a time.  I had another list of addresses that I could hold down the command button while selecting as many as desired, then click on BCC and double-click on just one of the addresses, and BCC would autofill with all of them.  Unfortunately, when I installed the latest Mac system update, I lost that multiple address capability--it's always something!

  • My iphone 4 says outgoing whenever i send an sms to multiple recipients.  does this mean it's still trying to send the message?

    my iphone 4 says outgoing whenever i send an sms to multiple recipients.  does this mean it's still trying to send the message?

    Perhaps someone from Apple could reply to this rather than leaving it unanswered?

  • TS3899 If I send an email to multiple recipients, I cannot open the individual replies on iphone

    If I send an email to multiple recipients, I cannot open the individual replies. I can see there are a few replies but have to go to webmail to see them.
    Any ideas anyone?

    ...and even email addresses can be hidden by sending to each recipient using your mail client's "bcc" or "blind copy" field instead of the "to" field.

  • How to send a document to multiple signers

    In this tutorial, learn how to send an agreement to multiple unique signers who are signing the same agreement.

    Ourdream wrote:
    even if I dont have word it can be sent as word?
    Yes, try Share > Send Via Mail

  • Send e-mail to multiple recipients that are entered in a form

    Hello,
    I wonder if somebody could help me...at least with the clue to do the following.
    I have a form, with a textarea , where the people should put the e-mail addreses of all the people that, later will receive all the form data via e-mail..
    I do not know how to retrieve all these e-mail addresses from the textarea (format?) and then how to send the e-mail to multiple recipients .
    It works for one...but I do not know how to do this for several recipients...
    could you please help?

    use string tokenizer to tokenize the string and then use this in ur smtp coding
    message.addRecipients(Message.RecipientType.TO, to)
    where 'message' is object of MimeMessage
    and 'to' is array of Address
    ex:-
    Address[] to = new Address[count];
    Earlier u must be using message.addRecipient(Message.RecipientType.TO, to)
    where to is object of Address.
    Sample code:-
    suppose String posted from ur form is :-
    to = "[email protected],[email protected],[email protected]"
    StringTokenizer toAdd = new StringTokenizer(to,",");
    Address[] address=new Address[toAdd.countTokens()];     
    int j=0;
    while(toAdd.hasMoreTokens()){
    address[j]=(new InternetAddress(toAdd.nextToken()));
    j++;
    }

  • How to send job postings to multiple third party sites using the XML output

    Dear Friends,
    We are Implementing Irecruitment for our client, Client requirement is how can we send job postings to multiple third party sites using the XML output from i-Recruitment
    With regards
    Surya
    .

    Can you be more specific about your Requirement. In General, Please navigate to iRecruitment Recruiter Responisbility.
    Then Select, Setup > Recruiting Sites. Here, you can configure your Third Party Websites information and attach stylesheets. The default mode oracle sends the vacancy information is HR-XML Format.
    If you would like to select more sites information select "Add Another Row".
    Then, you can see this information while "New Vacancy Creation Process".
    iRecruiter.
    Edited by: iRecruiter on Oct 18, 2009 7:43 AM

  • Sending Text Messages to Multiple Recipients

    Is there a way to send a text message to multiple recipients? I've been trying to figure it out for a while. I feel like this is a feature that apple couldn't have just forgotten! Anybody know?

    Not supported with the iPhone - at the present time anyway with no indication that it will be supported in the future.
    Apple is known for doing research so right, wrong or indifferent, I doubt this is something Apple forgot to include.
    The only thing you can do is provide Apple feedback via the iPhone feedback link.

  • TS3988 How do I create a List (multiple recipients) for my iCloud email?

    What steps must I take to create a List (multiple recipients) for my iCloud email?  I will be corresponding with a fied group of contacts over the course of a 3-month project.  I need to create a List/Alias that will send the same message to some 18-20 members of this group in a single email exchange.

    lets try this again. A PST file is an outlook file. Thunderbird does not and never has created them.
    https://addons.mozilla.org/en-US/thunderbird/addon/importexporttools/
    Use the add-on to export your mail as EML. This is a fairly standard format that just abut any mail client can read. Except Outlook.

  • How to send RTP packet through SIP Dialog

    Hello there !
    I work on a Java softphone which use JMF and Jain-SIP. I know JMF is "old" but I think it would be simple to capture and transmit RTP audio. So, my SIP dialog is working, I can send text messages but now, I would like to send RTP with this SIP session. I know I have to send SDP messages for codec convenience but then, what is the MediaLocator for RTP packet ? Only SIP User Agent IP or something else ?
    I also accept all ressources that can help me achieve my work :)

    I have no idea how SIP works, but, RTP packets go to an IP:PORT... theoretically, in the SIP phonecall setup, I'd imagine you'd have to be given the address to send RTP packets to the remote phone. Or perhaps the port is already well-defined by the SIP standard.
    Either way, you should have a way of knowing / finding out which PORT to send to for your SIP call, either from the call setup or the SIP standard itself.

  • How to send a packet through a specific Inferface ?

    Hello!
    I have 3 interfaces in my pc : LAN / WLAN / 3G
    On LAN I have a global IP.
    On WLAN and 3G I'm behind NAT.
    I'm coding a program (client+srv) >
    I watch a video streaming on LAN then I switch to WLAN or 3G and I want it to happen seamless. So basecly seamless vertical handover is my goal.
    Because I'm behind a NAT (3G,WLAN) First I have to send a packet to the server (connection initialization). When the server sends the stream to me it actually sends it to the NAT and the NAT will fwd it to me.
    The NAT send the packets back to me only if>
    1. the server sends from the same port which it received the request form the NAT
    2. It have to send to the same NAT (ip+port) address where the request came from
    3. NAT will send then the packet back to my PC to the same port where I sent my request from.
    Here comes my big problem!
    I have a socket bound to a IP1 and port (e.g. WLAN) if I want to send a packet to an destination IPx for which the route table has the LAN interface as default gateway (IP2), then it will send my packet trough the LAN (IP2) but the source IP will be IP1 in the packet.
    Basecly I have a WLAN package on my LAN.
    This is bad for me in 2 ways.
    1. there won't be a NAT binding for my WLAN
    2. the packet won't even make it to the server because the very first router will throw it away since it's source IP is not a LAN IP
    SO,
    is there a way in Java, to send a packet thorugh a specific interface???
    Thx for the kind help!
    r0hamkuka

    I used NetworkInterface.getNetworkInterfaces() to get all avaliable interfaces. After that I used this: interfaceSocket = new DatagramSocket(6000, interfaceIp); for all my interfaces with different interfaceIp of course
    The I tried to send a packet to 153.66.200.155 for example (LAN address) through my WLAN interface (ip for example: 192.168.1.101) using WLAN's interfaceSocket.send()
    But the packet goes out on my LAN interface (ip 153.66.200.166) while the src ip is still 192.168.1.101 in the packet. That is why I sad WLAN packet on LAN interface.
    I guess the reason is still the routing table. Because routing table tells which IF to use for a destination IP. Of course for dest 153.66.x.x routing table contains 153.66.200.166 as the gateway and not 192.168.1.101. So Win uses this the LAN IF to send the packet.

  • Any way to send a "forward" to multiple recipients and have each email addressed only to each individual?

    I want to forward an email to multiple recipients, but instead of putting them all in BCC:, I want all the recipients to get the forward addressed just to them so it looks personalized.  Any way to do this?

    I'm assuming that I would have to "import" my old drive into the library
    You don't import anything since your library is the same as it was. All those items are still in iTunes in the same location. The ONLY thing different is iTunes prefs -> Advanced.
    Or am I wrong and it will have my previous media folder still in the library, and anything new would be put in the new media folder?
    Yes & yes. Everything in iTunes will still be in iTunes, stay in the same location it is now and iTunes will use it from there.
    Anything new added to iTunes will go to the location you set in iTunes prefs -> Advanced.

Maybe you are looking for