SocketPermission error on broadcast.

A

Andrew Thompson

Eitan M wrote:
....
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.
 
E

Eitan M

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 :)
 
M

Mark Space

Andrew said:
Eitan M wrote:
...

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.
 
E

Eitan M

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 :)
 
M

Mark Space

Eitan said:
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 ?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top