title image


Smiley ... und noch ein Beispiel


// Allow only one instance of JustOne to run at a time.



import java.io.*;

import java.net.*;



public class JustOne

{ SimpleDummyServer sds = null;



public static void main(String args[])

{ new JustOne().doit();

}



public void doit()

{ try

{ Socket clientSocket = new Socket("localhost", SimpleDummyServer.port);

System.out.println("*** Already running!");

System.exit(1);

}

catch (Exception e)

{ sds = new SimpleDummyServer();

sds.start();

}

while(true)

{ try

{ System.out.print(".");

Thread.sleep(5*60);

}

catch(Exception e)

{ e.printStackTrace();

}

}

}

}



//////////////////////////////////////////////////



import java.io.*;

import java.net.*;



public class SimpleDummyServer extends Thread // SingleInstanceThread

{

public static final int port = 80;



ServerSocket serverSocket = null;

Socket clientSocket = null;



public void run()

{ try

{ // Create the server socket

serverSocket = new ServerSocket(port, 1);

while (true)

{ // Wait for a connection

clientSocket = serverSocket.accept();

System.out.println("*** Got a connection! ***");

clientSocket.close();

}

}

catch (IOException ioe)

{ System.out.println("Error in SimpleDummyServer: " + ioe);

}

}

}



geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: