Getting IOException receiving datagrampakcet through datagramsocket (Java)
up vote
0
down vote
favorite
I am trying to use a dagramsocket to send packages from a client to a server, but after spending some hours looking for information in StackOverflow and the offical documentation, I am still getting a IOException.
I have a server, with recieve a sentence from a client, change the sentence and print the new sentence. Any idea why it is not working? Here is the code:
Client:
public class YodafyClienteTCP {
public static void main(String args) {
byte buferEnvio;
byte buferRecepcion=new byte[256];
int bytesLeidos=0;
// Nombre del host donde se ejecuta el servidor:
String host="localhost";
// Puerto en el que espera el servidor:
int port=8989;
DatagramPacket paquete;
InetAddress direccion;
// Socket para la conexión TCP
DatagramSocket socketServicio;
try {
// Creamos un socket que se conecte a "host" y "port":
socketServicio=new DatagramSocket();
direccion = InetAddress.getByName(host);
buferEnvio="Al monte del volcán debes ir sin demora".getBytes();
paquete = new DatagramPacket(buferEnvio, buferEnvio.length, direccion, port);
// Enviamos el array por el socket;
socketServicio.send(paquete);
System.out.println("Paquete enviado por el cliente.");
socketServicio.close();
// Excepciones:
} catch (UnknownHostException e) {
System.err.println("Error: Nombre de host no encontrado.");
e.printStackTrace();
} catch (IOException e) {
System.err.println("Error de entrada/salida al abrir el socket.");
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
}
}
Class which change sentence, invoked by server
public class ProcesadorYodafy {
// Referencia a un socket para enviar/recibir las peticiones/respuestas
private DatagramSocket socketServicio;
// Para que la respuesta sea siempre diferente, usamos un generador de números aleatorios.
private Random random;
// Constructor que tiene como parámetro una referencia al socket abierto en por otra clase
public ProcesadorYodafy(DatagramSocket socketServicio) {
this.socketServicio=socketServicio;
random=new Random();
}
// Aquí es donde se realiza el procesamiento realmente:
void procesa(){
// Como máximo leeremos un bloque de 1024 bytes. Esto se puede modificar.
byte datosRecibidos=new byte[1024];
int bytesRecibidos=0;
DatagramPacket paquete;
// Array de bytes para enviar la respuesta. Podemos reservar memoria cuando vayamos a enviarla:
byte datosEnviar;
try {
// Lee la frase a Yodaficar:
paquete = new DatagramPacket(datosRecibidos, datosRecibidos.length);
socketServicio.receive(paquete);
datosRecibidos = paquete.getData();
bytesRecibidos = datosRecibidos.length;
//yodaDo is just a method that changes some characters in the sentence
String peticion=new String(datosRecibidos,0,bytesRecibidos);
String respuesta=yodaDo(peticion);
System.out.println("Here is your new sentence : " + respuesta);
socketServicio.close();
} catch (IOException e) {
System.err.println("Error al obtener los flujos de entrada/salida.");
}
}
Server:
public class YodafyServidorIterativo {
public static void main(String args) {
// Puerto de escucha
int port=8989;
// array de bytes auxiliar para recibir o enviar datos.
byte buffer=new byte[256];
// Número de bytes leídos
int bytesLeidos=0;
//Socket
DatagramSocket socketServicio;
try {
// Abrimos el socket en modo pasivo, escuchando el en puerto indicado por "port"
socketServicio = new DatagramSocket(port);
// Mientras ... siempre!
do {
//////////////////////////////////////////////////
// Creamos un objeto de la clase ProcesadorYodafy, pasándole como
// argumento el nuevo socket, para que realice el procesamiento
// Este esquema permite que se puedan usar hebras más fácilmente.
ProcesadorYodafy procesador=new ProcesadorYodafy(socketServicio);
procesador.procesa();
} while (true);
} catch (IOException e) {
System.err.println("Error al escuchar en el puerto "+port);
}
}
}
java udp ioexception
|
show 1 more comment
up vote
0
down vote
favorite
I am trying to use a dagramsocket to send packages from a client to a server, but after spending some hours looking for information in StackOverflow and the offical documentation, I am still getting a IOException.
I have a server, with recieve a sentence from a client, change the sentence and print the new sentence. Any idea why it is not working? Here is the code:
Client:
public class YodafyClienteTCP {
public static void main(String args) {
byte buferEnvio;
byte buferRecepcion=new byte[256];
int bytesLeidos=0;
// Nombre del host donde se ejecuta el servidor:
String host="localhost";
// Puerto en el que espera el servidor:
int port=8989;
DatagramPacket paquete;
InetAddress direccion;
// Socket para la conexión TCP
DatagramSocket socketServicio;
try {
// Creamos un socket que se conecte a "host" y "port":
socketServicio=new DatagramSocket();
direccion = InetAddress.getByName(host);
buferEnvio="Al monte del volcán debes ir sin demora".getBytes();
paquete = new DatagramPacket(buferEnvio, buferEnvio.length, direccion, port);
// Enviamos el array por el socket;
socketServicio.send(paquete);
System.out.println("Paquete enviado por el cliente.");
socketServicio.close();
// Excepciones:
} catch (UnknownHostException e) {
System.err.println("Error: Nombre de host no encontrado.");
e.printStackTrace();
} catch (IOException e) {
System.err.println("Error de entrada/salida al abrir el socket.");
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
}
}
Class which change sentence, invoked by server
public class ProcesadorYodafy {
// Referencia a un socket para enviar/recibir las peticiones/respuestas
private DatagramSocket socketServicio;
// Para que la respuesta sea siempre diferente, usamos un generador de números aleatorios.
private Random random;
// Constructor que tiene como parámetro una referencia al socket abierto en por otra clase
public ProcesadorYodafy(DatagramSocket socketServicio) {
this.socketServicio=socketServicio;
random=new Random();
}
// Aquí es donde se realiza el procesamiento realmente:
void procesa(){
// Como máximo leeremos un bloque de 1024 bytes. Esto se puede modificar.
byte datosRecibidos=new byte[1024];
int bytesRecibidos=0;
DatagramPacket paquete;
// Array de bytes para enviar la respuesta. Podemos reservar memoria cuando vayamos a enviarla:
byte datosEnviar;
try {
// Lee la frase a Yodaficar:
paquete = new DatagramPacket(datosRecibidos, datosRecibidos.length);
socketServicio.receive(paquete);
datosRecibidos = paquete.getData();
bytesRecibidos = datosRecibidos.length;
//yodaDo is just a method that changes some characters in the sentence
String peticion=new String(datosRecibidos,0,bytesRecibidos);
String respuesta=yodaDo(peticion);
System.out.println("Here is your new sentence : " + respuesta);
socketServicio.close();
} catch (IOException e) {
System.err.println("Error al obtener los flujos de entrada/salida.");
}
}
Server:
public class YodafyServidorIterativo {
public static void main(String args) {
// Puerto de escucha
int port=8989;
// array de bytes auxiliar para recibir o enviar datos.
byte buffer=new byte[256];
// Número de bytes leídos
int bytesLeidos=0;
//Socket
DatagramSocket socketServicio;
try {
// Abrimos el socket en modo pasivo, escuchando el en puerto indicado por "port"
socketServicio = new DatagramSocket(port);
// Mientras ... siempre!
do {
//////////////////////////////////////////////////
// Creamos un objeto de la clase ProcesadorYodafy, pasándole como
// argumento el nuevo socket, para que realice el procesamiento
// Este esquema permite que se puedan usar hebras más fácilmente.
ProcesadorYodafy procesador=new ProcesadorYodafy(socketServicio);
procesador.procesa();
} while (true);
} catch (IOException e) {
System.err.println("Error al escuchar en el puerto "+port);
}
}
}
java udp ioexception
1
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 at 20:10
I said I am getting an IOexception when I recieve the package, I don't know more about the problem
– vicase98
Nov 17 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 at 9:12
The exception has a specific error message and a stack trace, and you are discarding both. Usee.printStackTrace()
in your catch block.
– chrylis
Nov 18 at 21:10
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to use a dagramsocket to send packages from a client to a server, but after spending some hours looking for information in StackOverflow and the offical documentation, I am still getting a IOException.
I have a server, with recieve a sentence from a client, change the sentence and print the new sentence. Any idea why it is not working? Here is the code:
Client:
public class YodafyClienteTCP {
public static void main(String args) {
byte buferEnvio;
byte buferRecepcion=new byte[256];
int bytesLeidos=0;
// Nombre del host donde se ejecuta el servidor:
String host="localhost";
// Puerto en el que espera el servidor:
int port=8989;
DatagramPacket paquete;
InetAddress direccion;
// Socket para la conexión TCP
DatagramSocket socketServicio;
try {
// Creamos un socket que se conecte a "host" y "port":
socketServicio=new DatagramSocket();
direccion = InetAddress.getByName(host);
buferEnvio="Al monte del volcán debes ir sin demora".getBytes();
paquete = new DatagramPacket(buferEnvio, buferEnvio.length, direccion, port);
// Enviamos el array por el socket;
socketServicio.send(paquete);
System.out.println("Paquete enviado por el cliente.");
socketServicio.close();
// Excepciones:
} catch (UnknownHostException e) {
System.err.println("Error: Nombre de host no encontrado.");
e.printStackTrace();
} catch (IOException e) {
System.err.println("Error de entrada/salida al abrir el socket.");
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
}
}
Class which change sentence, invoked by server
public class ProcesadorYodafy {
// Referencia a un socket para enviar/recibir las peticiones/respuestas
private DatagramSocket socketServicio;
// Para que la respuesta sea siempre diferente, usamos un generador de números aleatorios.
private Random random;
// Constructor que tiene como parámetro una referencia al socket abierto en por otra clase
public ProcesadorYodafy(DatagramSocket socketServicio) {
this.socketServicio=socketServicio;
random=new Random();
}
// Aquí es donde se realiza el procesamiento realmente:
void procesa(){
// Como máximo leeremos un bloque de 1024 bytes. Esto se puede modificar.
byte datosRecibidos=new byte[1024];
int bytesRecibidos=0;
DatagramPacket paquete;
// Array de bytes para enviar la respuesta. Podemos reservar memoria cuando vayamos a enviarla:
byte datosEnviar;
try {
// Lee la frase a Yodaficar:
paquete = new DatagramPacket(datosRecibidos, datosRecibidos.length);
socketServicio.receive(paquete);
datosRecibidos = paquete.getData();
bytesRecibidos = datosRecibidos.length;
//yodaDo is just a method that changes some characters in the sentence
String peticion=new String(datosRecibidos,0,bytesRecibidos);
String respuesta=yodaDo(peticion);
System.out.println("Here is your new sentence : " + respuesta);
socketServicio.close();
} catch (IOException e) {
System.err.println("Error al obtener los flujos de entrada/salida.");
}
}
Server:
public class YodafyServidorIterativo {
public static void main(String args) {
// Puerto de escucha
int port=8989;
// array de bytes auxiliar para recibir o enviar datos.
byte buffer=new byte[256];
// Número de bytes leídos
int bytesLeidos=0;
//Socket
DatagramSocket socketServicio;
try {
// Abrimos el socket en modo pasivo, escuchando el en puerto indicado por "port"
socketServicio = new DatagramSocket(port);
// Mientras ... siempre!
do {
//////////////////////////////////////////////////
// Creamos un objeto de la clase ProcesadorYodafy, pasándole como
// argumento el nuevo socket, para que realice el procesamiento
// Este esquema permite que se puedan usar hebras más fácilmente.
ProcesadorYodafy procesador=new ProcesadorYodafy(socketServicio);
procesador.procesa();
} while (true);
} catch (IOException e) {
System.err.println("Error al escuchar en el puerto "+port);
}
}
}
java udp ioexception
I am trying to use a dagramsocket to send packages from a client to a server, but after spending some hours looking for information in StackOverflow and the offical documentation, I am still getting a IOException.
I have a server, with recieve a sentence from a client, change the sentence and print the new sentence. Any idea why it is not working? Here is the code:
Client:
public class YodafyClienteTCP {
public static void main(String args) {
byte buferEnvio;
byte buferRecepcion=new byte[256];
int bytesLeidos=0;
// Nombre del host donde se ejecuta el servidor:
String host="localhost";
// Puerto en el que espera el servidor:
int port=8989;
DatagramPacket paquete;
InetAddress direccion;
// Socket para la conexión TCP
DatagramSocket socketServicio;
try {
// Creamos un socket que se conecte a "host" y "port":
socketServicio=new DatagramSocket();
direccion = InetAddress.getByName(host);
buferEnvio="Al monte del volcán debes ir sin demora".getBytes();
paquete = new DatagramPacket(buferEnvio, buferEnvio.length, direccion, port);
// Enviamos el array por el socket;
socketServicio.send(paquete);
System.out.println("Paquete enviado por el cliente.");
socketServicio.close();
// Excepciones:
} catch (UnknownHostException e) {
System.err.println("Error: Nombre de host no encontrado.");
e.printStackTrace();
} catch (IOException e) {
System.err.println("Error de entrada/salida al abrir el socket.");
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
}
}
Class which change sentence, invoked by server
public class ProcesadorYodafy {
// Referencia a un socket para enviar/recibir las peticiones/respuestas
private DatagramSocket socketServicio;
// Para que la respuesta sea siempre diferente, usamos un generador de números aleatorios.
private Random random;
// Constructor que tiene como parámetro una referencia al socket abierto en por otra clase
public ProcesadorYodafy(DatagramSocket socketServicio) {
this.socketServicio=socketServicio;
random=new Random();
}
// Aquí es donde se realiza el procesamiento realmente:
void procesa(){
// Como máximo leeremos un bloque de 1024 bytes. Esto se puede modificar.
byte datosRecibidos=new byte[1024];
int bytesRecibidos=0;
DatagramPacket paquete;
// Array de bytes para enviar la respuesta. Podemos reservar memoria cuando vayamos a enviarla:
byte datosEnviar;
try {
// Lee la frase a Yodaficar:
paquete = new DatagramPacket(datosRecibidos, datosRecibidos.length);
socketServicio.receive(paquete);
datosRecibidos = paquete.getData();
bytesRecibidos = datosRecibidos.length;
//yodaDo is just a method that changes some characters in the sentence
String peticion=new String(datosRecibidos,0,bytesRecibidos);
String respuesta=yodaDo(peticion);
System.out.println("Here is your new sentence : " + respuesta);
socketServicio.close();
} catch (IOException e) {
System.err.println("Error al obtener los flujos de entrada/salida.");
}
}
Server:
public class YodafyServidorIterativo {
public static void main(String args) {
// Puerto de escucha
int port=8989;
// array de bytes auxiliar para recibir o enviar datos.
byte buffer=new byte[256];
// Número de bytes leídos
int bytesLeidos=0;
//Socket
DatagramSocket socketServicio;
try {
// Abrimos el socket en modo pasivo, escuchando el en puerto indicado por "port"
socketServicio = new DatagramSocket(port);
// Mientras ... siempre!
do {
//////////////////////////////////////////////////
// Creamos un objeto de la clase ProcesadorYodafy, pasándole como
// argumento el nuevo socket, para que realice el procesamiento
// Este esquema permite que se puedan usar hebras más fácilmente.
ProcesadorYodafy procesador=new ProcesadorYodafy(socketServicio);
procesador.procesa();
} while (true);
} catch (IOException e) {
System.err.println("Error al escuchar en el puerto "+port);
}
}
}
java udp ioexception
java udp ioexception
asked Nov 17 at 19:41
vicase98
234
234
1
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 at 20:10
I said I am getting an IOexception when I recieve the package, I don't know more about the problem
– vicase98
Nov 17 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 at 9:12
The exception has a specific error message and a stack trace, and you are discarding both. Usee.printStackTrace()
in your catch block.
– chrylis
Nov 18 at 21:10
|
show 1 more comment
1
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 at 20:10
I said I am getting an IOexception when I recieve the package, I don't know more about the problem
– vicase98
Nov 17 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 at 9:12
The exception has a specific error message and a stack trace, and you are discarding both. Usee.printStackTrace()
in your catch block.
– chrylis
Nov 18 at 21:10
1
1
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 at 20:10
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 at 20:10
I said I am getting an IOexception when I recieve the package, I don't know more about the problem
– vicase98
Nov 17 at 22:40
I said I am getting an IOexception when I recieve the package, I don't know more about the problem
– vicase98
Nov 17 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 at 23:38
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 at 9:12
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 at 9:12
The exception has a specific error message and a stack trace, and you are discarding both. Use
e.printStackTrace()
in your catch block.– chrylis
Nov 18 at 21:10
The exception has a specific error message and a stack trace, and you are discarding both. Use
e.printStackTrace()
in your catch block.– chrylis
Nov 18 at 21:10
|
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
0
down vote
First of all, this is a UDP connection, like mention here. Looking for the right connection you gonna find more fast the need documentation.
Second, probably your problem, whenever it is, is cause by:
- One of your services isn't start or
- You don't set the port of your client application and, thinking you're using this locally, can cause conflicts of resources.
Try to set the port of your client and make sure your server is started before start you client.
New contributor
Server is started before running the client, that's sure. I use the same port in server, client and the java class wich change the sentence sent in the package. So, maybe there is a problem because of using localhost?
– vicase98
Nov 17 at 22:42
1
The problem is use the same port, and, when you try to catch a package, the port is already in use. Get different ports for client and server and try again.
– Guilherme Souza
Nov 18 at 20:11
Now the error dissapears, but server remains waiting for a package, whose datagramsocket is binded to port 8989, but client is sending through the same host with different port, 8990, so server can't get the package. Which is also strange is that client don't wait in a recieve package statment, just continues and print the same sentence, with a small error. As a consequence, I don't know if it is using the same package, so, same data. or there is some kind of interference between packages
– vicase98
Nov 18 at 22:10
add a comment |
up vote
0
down vote
accepted
Solved. I was closing the datagramsocket in the class ProcesadorYodafy and opening the socket only once in the server, so in the following iteration of the loop, the datagramsocket was closed despite the fact I was sending there the package. Thanks everybody
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
First of all, this is a UDP connection, like mention here. Looking for the right connection you gonna find more fast the need documentation.
Second, probably your problem, whenever it is, is cause by:
- One of your services isn't start or
- You don't set the port of your client application and, thinking you're using this locally, can cause conflicts of resources.
Try to set the port of your client and make sure your server is started before start you client.
New contributor
Server is started before running the client, that's sure. I use the same port in server, client and the java class wich change the sentence sent in the package. So, maybe there is a problem because of using localhost?
– vicase98
Nov 17 at 22:42
1
The problem is use the same port, and, when you try to catch a package, the port is already in use. Get different ports for client and server and try again.
– Guilherme Souza
Nov 18 at 20:11
Now the error dissapears, but server remains waiting for a package, whose datagramsocket is binded to port 8989, but client is sending through the same host with different port, 8990, so server can't get the package. Which is also strange is that client don't wait in a recieve package statment, just continues and print the same sentence, with a small error. As a consequence, I don't know if it is using the same package, so, same data. or there is some kind of interference between packages
– vicase98
Nov 18 at 22:10
add a comment |
up vote
0
down vote
First of all, this is a UDP connection, like mention here. Looking for the right connection you gonna find more fast the need documentation.
Second, probably your problem, whenever it is, is cause by:
- One of your services isn't start or
- You don't set the port of your client application and, thinking you're using this locally, can cause conflicts of resources.
Try to set the port of your client and make sure your server is started before start you client.
New contributor
Server is started before running the client, that's sure. I use the same port in server, client and the java class wich change the sentence sent in the package. So, maybe there is a problem because of using localhost?
– vicase98
Nov 17 at 22:42
1
The problem is use the same port, and, when you try to catch a package, the port is already in use. Get different ports for client and server and try again.
– Guilherme Souza
Nov 18 at 20:11
Now the error dissapears, but server remains waiting for a package, whose datagramsocket is binded to port 8989, but client is sending through the same host with different port, 8990, so server can't get the package. Which is also strange is that client don't wait in a recieve package statment, just continues and print the same sentence, with a small error. As a consequence, I don't know if it is using the same package, so, same data. or there is some kind of interference between packages
– vicase98
Nov 18 at 22:10
add a comment |
up vote
0
down vote
up vote
0
down vote
First of all, this is a UDP connection, like mention here. Looking for the right connection you gonna find more fast the need documentation.
Second, probably your problem, whenever it is, is cause by:
- One of your services isn't start or
- You don't set the port of your client application and, thinking you're using this locally, can cause conflicts of resources.
Try to set the port of your client and make sure your server is started before start you client.
New contributor
First of all, this is a UDP connection, like mention here. Looking for the right connection you gonna find more fast the need documentation.
Second, probably your problem, whenever it is, is cause by:
- One of your services isn't start or
- You don't set the port of your client application and, thinking you're using this locally, can cause conflicts of resources.
Try to set the port of your client and make sure your server is started before start you client.
New contributor
New contributor
answered Nov 17 at 20:19
Guilherme Souza
1
1
New contributor
New contributor
Server is started before running the client, that's sure. I use the same port in server, client and the java class wich change the sentence sent in the package. So, maybe there is a problem because of using localhost?
– vicase98
Nov 17 at 22:42
1
The problem is use the same port, and, when you try to catch a package, the port is already in use. Get different ports for client and server and try again.
– Guilherme Souza
Nov 18 at 20:11
Now the error dissapears, but server remains waiting for a package, whose datagramsocket is binded to port 8989, but client is sending through the same host with different port, 8990, so server can't get the package. Which is also strange is that client don't wait in a recieve package statment, just continues and print the same sentence, with a small error. As a consequence, I don't know if it is using the same package, so, same data. or there is some kind of interference between packages
– vicase98
Nov 18 at 22:10
add a comment |
Server is started before running the client, that's sure. I use the same port in server, client and the java class wich change the sentence sent in the package. So, maybe there is a problem because of using localhost?
– vicase98
Nov 17 at 22:42
1
The problem is use the same port, and, when you try to catch a package, the port is already in use. Get different ports for client and server and try again.
– Guilherme Souza
Nov 18 at 20:11
Now the error dissapears, but server remains waiting for a package, whose datagramsocket is binded to port 8989, but client is sending through the same host with different port, 8990, so server can't get the package. Which is also strange is that client don't wait in a recieve package statment, just continues and print the same sentence, with a small error. As a consequence, I don't know if it is using the same package, so, same data. or there is some kind of interference between packages
– vicase98
Nov 18 at 22:10
Server is started before running the client, that's sure. I use the same port in server, client and the java class wich change the sentence sent in the package. So, maybe there is a problem because of using localhost?
– vicase98
Nov 17 at 22:42
Server is started before running the client, that's sure. I use the same port in server, client and the java class wich change the sentence sent in the package. So, maybe there is a problem because of using localhost?
– vicase98
Nov 17 at 22:42
1
1
The problem is use the same port, and, when you try to catch a package, the port is already in use. Get different ports for client and server and try again.
– Guilherme Souza
Nov 18 at 20:11
The problem is use the same port, and, when you try to catch a package, the port is already in use. Get different ports for client and server and try again.
– Guilherme Souza
Nov 18 at 20:11
Now the error dissapears, but server remains waiting for a package, whose datagramsocket is binded to port 8989, but client is sending through the same host with different port, 8990, so server can't get the package. Which is also strange is that client don't wait in a recieve package statment, just continues and print the same sentence, with a small error. As a consequence, I don't know if it is using the same package, so, same data. or there is some kind of interference between packages
– vicase98
Nov 18 at 22:10
Now the error dissapears, but server remains waiting for a package, whose datagramsocket is binded to port 8989, but client is sending through the same host with different port, 8990, so server can't get the package. Which is also strange is that client don't wait in a recieve package statment, just continues and print the same sentence, with a small error. As a consequence, I don't know if it is using the same package, so, same data. or there is some kind of interference between packages
– vicase98
Nov 18 at 22:10
add a comment |
up vote
0
down vote
accepted
Solved. I was closing the datagramsocket in the class ProcesadorYodafy and opening the socket only once in the server, so in the following iteration of the loop, the datagramsocket was closed despite the fact I was sending there the package. Thanks everybody
add a comment |
up vote
0
down vote
accepted
Solved. I was closing the datagramsocket in the class ProcesadorYodafy and opening the socket only once in the server, so in the following iteration of the loop, the datagramsocket was closed despite the fact I was sending there the package. Thanks everybody
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Solved. I was closing the datagramsocket in the class ProcesadorYodafy and opening the socket only once in the server, so in the following iteration of the loop, the datagramsocket was closed despite the fact I was sending there the package. Thanks everybody
Solved. I was closing the datagramsocket in the class ProcesadorYodafy and opening the socket only once in the server, so in the following iteration of the loop, the datagramsocket was closed despite the fact I was sending there the package. Thanks everybody
answered 2 days ago
vicase98
234
234
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354878%2fgetting-ioexception-receiving-datagrampakcet-through-datagramsocket-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 at 20:10
I said I am getting an IOexception when I recieve the package, I don't know more about the problem
– vicase98
Nov 17 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 at 9:12
The exception has a specific error message and a stack trace, and you are discarding both. Use
e.printStackTrace()
in your catch block.– chrylis
Nov 18 at 21:10