• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can DatagramSocket work in applets

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)

------------------
Laurent Leonard
Laurent.Leonard@belgique.com
 
Ramneek Handa
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic