Hi, I want to use UDP in applet. below is the part code of the applet. It compiles fine and while running it throws NullPointerException at clientSocket.send(datagram); line. DatagramSocketclientSocket; DatagramPacketdatagram; System.out.println( "Connecting to Server ..." ); destination=InetAddress.getByName("rhanda"); // msg here are byte array object datagram=new DatagramPacket(msg,msg.length,destination , 5001); clientSocket.send(datagram); Can we use DatagramSocket in applets if can then what can be the reason for giving its NullPointerException. sooner replies will be highly appriciated. regards, Ramneek Handa.
Srikanth Remani
Greenhorn
Joined: Jun 08, 2001
Posts: 4
posted
0
Hi, Is the Destination your Server url ie is the UDP connection to the Same server on which your applet is there. Because for security reasons Applets are not allowed to establish socket connetions with other Servers if this is the Same server I believe UDP should work...
cheers Srikanth
Ramneek Handa
Ranch Hand
Joined: Nov 10, 2000
Posts: 44
posted
0
Hi Srikanth, The servers are same for that. but as i mentioned when I run applet it gives nullpointerexception. which should not come form connection problem. rgds, Ramneek
Laurent Leonard
Ranch Hand
Joined: May 15, 2001
Posts: 35
posted
0
DatagramSocketclientSocket; DatagramPacketdatagram; System.out.println( "Connecting to Server ..." ); destination=InetAddress.getByName("rhanda"); // msg here are byte array object datagram=new DatagramPacket(msg,msg.length,destination , 5001); clientSocket.send(datagram); When do you initialize clientSocket ? Why not getting the host URL with "Applet.getCodeBase()" instead of hardcoding ? What happen if destination is null ? (why not testing it, before using it)
Originally posted by Laurent Leonard: When do you initialize clientSocket ? Why not getting the host URL with "Applet.getCodeBase()" instead of hardcoding ? What happen if destination is null ? (why not testing it, before using it)
Thanks the problem was that I did not initialize clientSocket. and I had done hardcoding for giving exp. only and not wrote the testing code here to keep it shorter. but overall problem was not solved 'coz the motive was not make connection between server and the applet which is behind firewall.