Getting IOException receiving datagrampakcet through datagramsocket (Java)
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
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 '18 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 '18 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 '18 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 '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 '18 at 21:10
|
show 1 more comment
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 '18 at 19:41
vicase98vicase98
306
306
1
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 '18 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 '18 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 '18 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 '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 '18 at 21:10
|
show 1 more comment
1
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 '18 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 '18 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 '18 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 '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 '18 at 21:10
1
1
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 '18 at 20:10
You should post the specific error, not just "there was an error".
– chrylis
Nov 17 '18 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 '18 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 '18 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 '18 at 23:38
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 '18 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 '18 at 9:12
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 '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 '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 '18 at 21:10
|
show 1 more comment
2 Answers
2
active
oldest
votes
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.
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 '18 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 '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 '18 at 22:10
add a comment |
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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 '18 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 '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 '18 at 22:10
add a comment |
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.
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 '18 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 '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 '18 at 22:10
add a comment |
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.
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.
answered Nov 17 '18 at 20:19
Guilherme SouzaGuilherme Souza
1
1
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 '18 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 '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 '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 '18 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 '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 '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 '18 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 '18 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 '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 '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 '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 '18 at 22:10
add a comment |
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 |
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 |
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 Nov 19 '18 at 19:33
vicase98vicase98
306
306
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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 '18 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 '18 at 22:40
That's because you're catching it and then failing to print out any of its information.
– chrylis
Nov 17 '18 at 23:38
So, the exception is not because I am getting wrong the package, the error is somewhere else?
– vicase98
Nov 18 '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 '18 at 21:10