java - serverSocket not listening -


serversocket not listening on port of localhost, tried several ports. without timeout line not working. please suggest modifications in code.

public class server1 extends japplet implements serializable{  static japplet japplet = new japplet(); private static serversocket serversocket = null; private static socket clientsocket = null; private static final int maxclientscount = 5; private static final clientthread[] threads = new clientthread[maxclientscount];  public void init() {     tool = toolkit.getdefaulttoolkit();     setup_applet();     setup_layout();     run(); }  public void run() {     try {         serversocket = new serversocket(6789);         serversocket.setsotimeout(60000);      while (true) {         screen.init_screen();         clientsocket = serversocket.accept();              int = 0;             (i = 0; < maxclientscount; i++) {                 if (threads[i] == null) {                     (threads[i] = new clientthread(clientsocket, threads))                             .start();                     break;                 }             }             if (i == maxclientscount) {                 clientsocket.close();             }         }     } catch (ioexception e) {         system.out.println(e);     } } }  class clientthread extends thread implements serializable {  private string clientname = null; private printstream os = null; private socket clientsocket = null; private final clientthread[] threads; private int maxclientscount;  public clientthread(socket clientsocket, clientthread[] threads) {     this.clientsocket = clientsocket;     this.threads = threads;     maxclientscount = threads.length; }  public void run() {     int maxclientscount = this.maxclientscount;     clientthread[] threads = this.threads;      try {         os = new printstream(clientsocket.getoutputstream());          while (true) {             string msg = "server:apl";             synchronized (this) {                 (int = 0; < maxclientscount; i++) {                     if (threads[i] != null && threads[i] == this) {                         os.println(msg);                         break;                     }                 }             }             synchronized (this) {                 (int = 0; < maxclientscount; i++) {                     if (threads[i] != null && threads[i] !=                             && threads[i].clientname != null) {                         bufferedimage image = imageio.read(clientsocket.getinputstream());                         if(image != null) {                             soms1.screen.paint(image.getgraphics());                         } else {                             system.out.println("failed get");                         }                     }                 }             }             os.close();         }     } catch (ioexception e) {         system.out.println(e); } } 

i checked firewall , if ports not been used process. appreciated

this comes no surprise. application have developed java applet. means usual execution container run in web-browser. of course java browser plugin has pose security restrictions on applets running in users browser. otherwise applets perfect way ship malicious code users.

the protection mechanism called sandboxing. poses many restrictions, restriction important in context is, applet allowed open network connections host , port came from. means can make http calls server loaded from. details see documentation here: http://docs.oracle.com/javase/tutorial/deployment/applet/security.html

however, can sign applet explained here, rid of these restrictions: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/rsa_signing.html signed applets existing manifest file parsed. http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/manifest.html

long answer short: sign applet , should go.


Comments