import java.io.*;
import java.net.*;
import java.util.*;
public class Negoziazione{
public Negoziazione(String comando, String device_id, String ip) throws UnknownHostException, IOException{
// send request
byte[] buf = new byte[27];
DatagramSocket socket = new DatagramSocket();
InetAddress address = InetAddress.getByName(ip);
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 1000);
packet.setData(comando.getBytes());
socket.send(packet);
// get response
packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
// display response
String received = new String(packet.getData());
System.out.println("Ricevuto: " + received);
socket.close();
}
}
Il dato viene spedito (comando.getBytes()) ma il dispositivo che funziona da server udp risponde con udp_open error.
C'è qualcosa di sbagliato nel mio codice?
Quello del server udp non è dato saperlo e funziona sicuramente.
Qualche idea?