Re: udp multithreading
- From: Steve Horsley <steve.horsley@xxxxxxxxx>
- Date: Mon, 27 Feb 2006 23:15:10 +0000
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
.
- References:
- udp multithreading
- From: palmis
- udp multithreading
- Prev by Date: Re: POSSIBLE SECURITY PROBLEM in Java 5!
- Next by Date: Re: trustAnchors parameter error?
- Previous by thread: Re: udp multithreading
- Next by thread: Re: udp multithreading
- Index(es):
Relevant Pages
|