udp multithreading

Discussion in 'Java' started by palmis, Feb 27, 2006.

  1. palmis

    palmis Guest

    I want to send monitoring messages using udp protocol.
    I have to monitor many systems in the same moment, so I have to send
    monitoring messages in the same moment. but I have a problem:
    The udp receiver, receives the messages of the last system selected to
    monitor and not of the all systems monitored.

    why?
    I have to use thread?

    thanks
    Palmis
    This is the code

    import java.net.*;

    /**
    * Questa classe effettua la connessione UDP per l'invio dei messaggi
    ciclici di
    * monitoring.
    * @author Palmisano Francesca.
    */
    public class SenderUdp {

    // Numero di porta dell'host al quale connettersi. Il valore e'
    prelevato
    // dal file di configurazione.
    public static String port_string = "";

    // Indirizzo Ip dell'host al quale connettersi. Il valore e' prelevato
    dal
    // file di configurazione.
    public static String address_string = "";

    /**
    * Questo metodo e' il costruttore della classe.
    */
    public SenderUdp() {
    }

    /**
    * Questo metodo effettua la connessione UDP.
    * @param messageSend rappresenta il messaggio in input da inviare.
    */
    public static void connection(byte[] messageSend) {
    try {
    // Crea un datagram Packet
    InetAddress address = InetAddress.getByName(address_string);
    int port = Integer.parseInt(port_string);
    DatagramPacket dp = new DatagramPacket(messageSend,
    messageSend.length, address, port);

    // Crea un datagram Socket
    DatagramSocket ds = new DatagramSocket();

    // Invia al server il datagram packet
    ds.send(dp);
    return;
    } catch (Exception e) {
    e.printStackTrace();
    }
    }// Fine metodo connection()
    }
     
    palmis, Feb 27, 2006
    #1
    1. Advertising

  2. palmis

    ponce Guest

    maybe because transmission over UDP is not reliable... and hence some
    packets are lost

    palmis wrote:
    > I want to send monitoring messages using udp protocol.
    > I have to monitor many systems in the same moment, so I have to send
    > monitoring messages in the same moment. but I have a problem:
    > The udp receiver, receives the messages of the last system selected to
    > monitor and not of the all systems monitored.
    >
    > why?
    > I have to use thread?
    >
    > thanks
    > Palmis
    > This is the code
    >
    > import java.net.*;
    >
    > /**
    > * Questa classe effettua la connessione UDP per l'invio dei messaggi
    > ciclici di
    > * monitoring.
    > * @author Palmisano Francesca.
    > */
    > public class SenderUdp {
    >
    > // Numero di porta dell'host al quale connettersi. Il valore e'
    > prelevato
    > // dal file di configurazione.
    > public static String port_string = "";
    >
    > // Indirizzo Ip dell'host al quale connettersi. Il valore e' prelevato
    > dal
    > // file di configurazione.
    > public static String address_string = "";
    >
    > /**
    > * Questo metodo e' il costruttore della classe.
    > */
    > public SenderUdp() {
    > }
    >
    > /**
    > * Questo metodo effettua la connessione UDP.
    > * @param messageSend rappresenta il messaggio in input da inviare.
    > */
    > public static void connection(byte[] messageSend) {
    > try {
    > // Crea un datagram Packet
    > InetAddress address = InetAddress.getByName(address_string);
    > int port = Integer.parseInt(port_string);
    > DatagramPacket dp = new DatagramPacket(messageSend,
    > messageSend.length, address, port);
    >
    > // Crea un datagram Socket
    > DatagramSocket ds = new DatagramSocket();
    >
    > // Invia al server il datagram packet
    > ds.send(dp);
    > return;
    > } catch (Exception e) {
    > e.printStackTrace();
    > }
    > }// Fine metodo connection()
    > }
    >
     
    ponce, Feb 27, 2006
    #2
    1. Advertising

  3. palmis wrote:
    > I want to send monitoring messages using udp protocol.
    > I have to monitor many systems in the same moment, so I have to send
    > monitoring messages in the same moment. but I have a problem:
    > The udp receiver, receives the messages of the last system selected to
    > monitor and not of the all systems monitored.
    >
    > why?
    > I have to use thread?
    >
    > thanks
    > Palmis
    > This is the code
    >
    > import java.net.*;
    >
    > /**
    > * Questa classe effettua la connessione UDP per l'invio dei messaggi
    > ciclici di
    > * monitoring.
    > * @author Palmisano Francesca.
    > */
    > public class SenderUdp {
    >
    > // Numero di porta dell'host al quale connettersi. Il valore e'
    > prelevato
    > // dal file di configurazione.
    > public static String port_string = "";
    >
    > // Indirizzo Ip dell'host al quale connettersi. Il valore e' prelevato
    > dal
    > // file di configurazione.
    > public static String address_string = "";
    >
    > /**
    > * Questo metodo e' il costruttore della classe.
    > */
    > public SenderUdp() {
    > }
    >
    > /**
    > * Questo metodo effettua la connessione UDP.
    > * @param messageSend rappresenta il messaggio in input da inviare.
    > */
    > public static void connection(byte[] messageSend) {
    > try {
    > // Crea un datagram Packet
    > InetAddress address = InetAddress.getByName(address_string);
    > int port = Integer.parseInt(port_string);
    > DatagramPacket dp = new DatagramPacket(messageSend,
    > messageSend.length, address, port);
    >
    > // Crea un datagram Socket
    > DatagramSocket ds = new DatagramSocket();
    >
    > // Invia al server il datagram packet
    > ds.send(dp);
    > return;
    > } catch (Exception e) {
    > e.printStackTrace();
    > }
    > }// Fine metodo connection()
    > }
    >


    It looks like you are trying to create a new socket for each
    remote host, or even each packet sent - I'm not sure which. You
    shouldn't. Just create one socket for sending to all the remote
    hosts. Ican't remember whether you create each DatagramPacket
    with a different address/port, or whether you use sendTo() now,
    but either way you only need one socket. And the same socket can
    be used to receive packets from all remotes. Just check where
    each packet came from.

    Steve
     
    Steve Horsley, Feb 27, 2006
    #3
  4. palmis

    EJP Guest

    Nothing wrong with your sending code apart from what Steve wrote, but
    what does your receiving code do?
     
    EJP, Feb 28, 2006
    #4
  5. palmis

    palmis Guest

    thank you.
    I have solved my problem.
    It's true! In the code posted there isn't any error.
    I wrong to create new messages monitoring when chenge the subsystem
    monitored.

    Palmis
     
    palmis, Mar 1, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Boris Condarco

    Multithreading

    Boris Condarco, Jun 28, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    629
    Boris Condarco
    Jun 30, 2003
  2. Ilia
    Replies:
    6
    Views:
    3,043
    John Saunders
    Nov 4, 2003
  3. Fieldadvice

    Multithreading with HttpWebRequest

    Fieldadvice, Nov 6, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,400
  4. Muralidharan Ramakrishnan

    MultiThreading

    Muralidharan Ramakrishnan, Nov 10, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    432
    Kevin Spencer
    Nov 10, 2003
  5. BoomWackaBoom

    Asynchronous requests vs. multithreading

    BoomWackaBoom, Nov 14, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    689
    Alvin Bruney
    Nov 15, 2003
Loading...

Share This Page