Ciao a tutti! sto cercando di creare una piccola applet molto semplice (immagino, anche se io non riesco) per inviare messaggi UDP ad un certo ip e ad una certa porta e riuscire anche a leggerli... ho scritto questo e messo dei printLn per debuggare e sembra che invia il messaggio ma non riesce a riceverlo.. cosa sbaglio?
codice:import java.io.*; import java.net.*; import java.applet.*; public class UDPClient extends Applet { protected DatagramSocket socket = null; protected DatagramPacket packet = null; String ipAddress = "127.0.0.1"; public void init() { try{ socket = new DatagramSocket(); sendPacket(); receivePacket(); }catch(Exception e){e.printStackTrace();} } public void sendPacket() throws IOException { byte[] buf ="prova".getBytes(); InetAddress address = InetAddress.getByName(ipAddress); packet = new DatagramPacket(buf, buf.length, address, 5556); System.out.println("sending packet"); socket.send(packet); } public void receivePacket() throws IOException { byte[] buf = new byte[256]; packet = new DatagramPacket(buf, buf.length); System.out.println("getting packet--- calling socket.receive"); socket.receive(packet); System.out.println("got here, receiving packet"); } }

) per inviare messaggi UDP ad un certo ip e ad una certa porta e riuscire anche a leggerli... ho scritto questo e messo dei printLn per debuggare e sembra che invia il messaggio ma non riesce a riceverlo.. cosa sbaglio?
Rispondi quotando