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