Ok heres my story. A long time ago(some of you might remember me) i made a java game that used sockets and I could test it all on the same machine. For some reason I cannot get it to work now even though I'm 99% sure the code has not changed.
So i made a simple example and I cannot even get this to work.
Here is the server side application:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| import java.io.*; import java.net.*;
class simpleServer { public static void main(String args[]) { System.out.println("Server Running..."); new server().start(); } }
class server extends Thread { ServerSocket ssock; Socket csock;
public server() { try { ssock = new ServerSocket(4358); } catch (IOException e) { System.out.println("Couldn't access port"); System.exit(1); } } public void run() { while (true) { if(ssock == null) { System.out.println("Port Disappeared"); System.exit(1); } try { csock = ssock.accept(); System.out.println("someone connected! :)"); } catch (IOException e) { System.out.println("Couldn't connect player"); System.exit(1); } } }
} |
and the client applet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| import java.net.*; import java.applet.*; import java.io.*;
public class test extends Applet { Socket socket = null;
public void init() { try { socket = new Socket("localhost",4358); } catch (UnknownHostException ex) { System.out.println("Unknown host"); System.exit(1); } catch (IOException exx) { System.out.println("Read Failed"); System.exit(1); } } } |
All i am trying to do is create the connection but I contnue to throw the socket permission exception or something like that.
Shouldn't this work? Again this is all on the same machine. I start the server application and then launch the applet from an html file.
Any help would be greatly appreciated.