Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

SocketPermission error on broadcast.

Thread view: 
Eitan M - 21 Jul 2006 10:24 GMT
Hello,

I am trying to broadcast a message.
When I am doing this (on FORTE IDE),
everything works fine, and I am not getting any exception.

When I am trying the follows, and running from the command line :
In Java code :
try{
       serverSocket = new DatagramSocket();
}
catch (SocketException e){
  e.printStackTrace();
}
...

try {
DatagramPacket packet;
       byte[] buf = new byte[256];
       buf = s.getBytes();
       try {
           packet = new DatagramPacket(buf, buf.length,
               InetAddress.getByName("240.0.0.1"),
               2222);
           serverSocket.send(packet);
       }
       catch(UnknownHostException e) {// case 1
           JOptionPane.showMessageDialog(null, "1.broadcast error :"
+e.getMessage());
       }
       catch(IOException e) {// case 2
           JOptionPane.showMessageDialog(null, "2.broadcast error :"
+e.getMessage());
       }
       catch(Exception e){// case 3
           JOptionPane.showMessageDialog(null, "3.broadcast error :"
+e.getMessage());
       }

the last case(case 3) is catched.
Why ?
and why in

I get the exception message :
access denied (java.net.SocketPermission 240.0.0.1:2222 connect,resolve)

Why ?
And what should I do in order to solve the problem ?

Thanks :)
Andrew Thompson - 21 Jul 2006 10:47 GMT
...
> I am trying to broadcast a message.
> When I am doing this (on FORTE IDE),
> everything works fine, and I am not getting any exception.
>
> When I am trying the follows, and running from the command line :
> In Java code :
....
> I get the exception message :
> access denied (java.net.SocketPermission 240.0.0.1:2222 connect,resolve)
>
> Why ?

Usually this type of error happens when a developer switches
from running code that does not invoke any security manager,
into an applet, or WebStarted application or applet.

But that does not quite fit your description - that it fails
when run from the command line.  An application launched
from the command line should have no security manager,
or at least - it should be able to do anything that can be
done by running the code direct from the IDE.

> And what should I do in order to solve the problem ?

If you get no solution, you might try posting a complete,
compilable example so that we can investigate further.

Andrew T.
Mark Space - 21 Jul 2006 18:00 GMT
> ...
>> I am trying to broadcast a message.
[quoted text clipped - 6 lines]
>> I get the exception message :
>> access denied (java.net.SocketPermission 240.0.0.1:2222 connect,resolve)

Total off the cut guess, but broadcast address are fixed by the TCP/IP
protocol.  Are you sure this is a valid broadcast address for the
network in question?  Is it your network or someone else's?  Sending a
broadcast to another network may not be implemented in TCP/IP, so if
it's not your network, that may explain the permission denied part.

Ok I actually did a search, because I thought the IP address looked
funny.  That's a multi-cast address, not a broadcast.  I'm pretty sure,
with out doing any more research, that multicasting is not guaranteed to
be implemented, and often isn't.  YMMV.
Eitan M - 21 Jul 2006 20:15 GMT
It just an experiment to learn how things work.
(Besides - not 240.0.0.1, but 239.0.0.1,
just a random number i pick up between 224.0.0.0 - 239.255.255.255,
The same problem stays ...)
It may be not as simple as that (I should probebly configure a web-server
for that).
How can I make the simpliest broadcast station on internet using above ports
and methods ?

Thanks :)

>> ...
>>> I am trying to broadcast a message.
[quoted text clipped - 17 lines]
> doing any more research, that multicasting is not guaranteed to be
> implemented, and often isn't.  YMMV.
Mark Space - 22 Jul 2006 04:57 GMT
> It just an experiment to learn how things work.
> (Besides - not 240.0.0.1, but 239.0.0.1,
[quoted text clipped - 4 lines]
> How can I make the simpliest broadcast station on internet using above ports
> and methods ?

I haven't done any low level network programming on Java, but best as I
can remember, 255.255.255.255 is always the default broadcast address
for any network.  Routers won't forward that (they can't) but any local
machines should receive a packet. Port: can't remember if ports work for
broadcast or not, but try it. Just pick a port #, broadcast and listen
on the same port #, see if it goes.

You should really get some info on basic TCP/IP stuff, like how it works
and all.  My books are packed away at the moment, but try a Google
search for TCP tutorial or some such.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.