|
|
Java networking question
|
|
|
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Hi all. I'm having trouble getting a client-server java program working between two machines (it works okay if both the server and client are local, but that's not very exciting).
Here's an example of what my client connection code looks like:
Code:
try
{
InetAddress address = InetAddress.getByName(IP);
Socket s = SocketFactory.getDefault().createSocket(address, PORT);
}
catch(Exception e)
{
System.out.println("connectToServer: " + e);
}
And my server of course is just sitting around waiting for connections. When I try to connect, I get this error:
connectToServer: java.security.AccessControlException: access denied (java.net.SocketPermission **.**.***.**:**** connect,resolve)
where the ip address I want to connect to has has been edited out, along with the port.
And if I nmap my server:
sudo /sw/bin/nmap -sX -p **** **.**.***.**
I get that the port in question is open. I can even ssh to the server machine from my client machine, no problem.
I've opened up the port I want to connect to in the Sharing preferences... is there something else I have to do to get my server working?
Thanks,
Matt Fahrenbacher
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Some more info -
If I run the server on my client machine
And I run the applet off of my local machine through a webpage that is local to my machine, it works
If I run the server on my client machine
And I run the applet off of my .Mac account through Safari on my local machine, I get the same error.
Does that help?
Thanks,
Matt Fahrenbacher
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
You should be able to just do:
Code:
Socket s = new Socket(address, PORT);
I'm not sure how the factory method differs from the constructor, but you could see if that makes a difference.
Also, make sure that "address" is resolving to the host you think it is. You should be able to pass an IP into the address field as well as the name.
If you want to post some skeleton code, I'll be happy to compile it locally and look for problems.
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Feb 2004
Status:
Offline
|
|
Originally posted by Ghoser777:
Some more info -
If I run the server on my client machine
And I run the applet off of my local machine through a webpage that is local to my machine, it works
If I run the server on my client machine
And I run the applet off of my .Mac account through Safari on my local machine, I get the same error.
Unsigned Applets can only establish connections to the machine where they came from. I.e. the server must run on the same machine as the webpage...
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Okay, interesting results. I took the KnockKnock example and tried having the server on one machine and the client on another like I did with my other program... and it worked.
On a correct hunch, I was able to get the same error to come up again if I made the KnockKnockClient a subclass of JApplet. Is there server side security thing for applets that I need to disable?
Thanks,
Matt Fahrenbacher
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Originally posted by bone666:
Unsigned Applets can only establish connections to the machine where they came from. I.e. the server must run on the same machine as the webpage...
Okay, so now I'm doing some google searches on how to accomplish signing... although this sounds like not so much fun.
Matt Fahrenbacher
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
OH! So if I put the Server code on the same machine as the client code, and then load the applet from another website, then it will work!
Could someone try to login to here and tell me if this works for them (I want to make sure it works outside my network):
http://24.15.249.34/FMessenger.html
name: Colby
passwd: Colby
Thanks!
Matt Fahrenbacher
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Originally posted by Ghoser777:
OH! So if I put the Server code on the same machine as the client code, and then load the applet from another website, then it will work!
Could someone try to login to here and tell me if this works for them (I want to make sure it works outside my network):
http://24.15.249.34/FMessenger.html
name: Colby
passwd: Colby
Safari says I can't connect to the server.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
That's because my dad turned off my server - I already checked with someone else, it works great!
Thanks,
Matt Fahrenbacher
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|