Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Java networking question

Java networking question
Thread Tools
Ghoser777
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 3, 2004, 10:48 AM
 
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
     
Ghoser777  (op)
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 3, 2004, 12:37 PM
 
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
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Apr 3, 2004, 02:16 PM
 
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
     
bone666
Fresh-Faced Recruit
Join Date: Feb 2004
Status: Offline
Reply With Quote
Apr 3, 2004, 02:31 PM
 
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...
     
Ghoser777  (op)
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 3, 2004, 02:40 PM
 
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
     
Ghoser777  (op)
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 3, 2004, 02:43 PM
 
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
     
Ghoser777  (op)
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 3, 2004, 03:07 PM
 
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
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 4, 2004, 07:01 AM
 
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'."
     
Ghoser777  (op)
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 4, 2004, 01:08 PM
 
That's because my dad turned off my server - I already checked with someone else, it works great!

Thanks,
Matt Fahrenbacher
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:13 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,