List of usage examples for java.net ServerSocket accept
public Socket accept() throws IOException
From source file:MainClass.java
public static void main(String[] args) throws Exception { ServerSocketFactory ssf = SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(9096); while (true) { new SSLSimpleServer(ss.accept()).start(); }// ww w. ja v a 2 s.c om }
From source file:AnotherBeerServer.java
public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(1234); System.out.println("Listening"); Socket sock = ssock.accept(); ssock.close(); // no more connects PrintStream ps = new PrintStream(sock.getOutputStream()); // ask for count ps.print("count? "); BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream())); // read and parse it String line = input.readLine(); ps.println(""); int count = Integer.parseInt(line); for (int i = count; i >= 0; i--) { ps.println(i + " Java Source and Support."); }//from w w w . j ava2s . c om ps.close(); sock.close(); }
From source file:MTServerBase.java
static public void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(8080); while (true) { Socket esock = null;/*from w ww. j a va2s.co m*/ esock = ssock.accept(); MTServerBase t = new MTServerBase(); t.socket = esock; t.start(); esock.close(); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { System.setProperty("javax.net.ssl.keyStore", "lfkeystore2"); System.setProperty("javax.net.ssl.keyStorePassword", "wshr.ut"); SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(5432); while (true) { Socket s = ss.accept(); SSLSession session = ((SSLSocket) s).getSession(); Certificate[] cchain2 = session.getLocalCertificates(); for (int i = 0; i < cchain2.length; i++) { System.out.println(((X509Certificate) cchain2[i]).getSubjectDN()); }/*from w ww. ja va 2 s . c o m*/ System.out.println("Peer host is " + session.getPeerHost()); System.out.println("Cipher is " + session.getCipherSuite()); System.out.println("Protocol is " + session.getProtocol()); System.out.println("ID is " + new BigInteger(session.getId())); System.out.println("Session created in " + session.getCreationTime()); System.out.println("Session accessed in " + session.getLastAccessedTime()); PrintStream out = new PrintStream(s.getOutputStream()); out.println("Hi"); out.close(); s.close(); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SSLContext context;// w w w . j ava 2s .co m KeyManagerFactory kmf; KeyStore ks; char[] storepass = "newpass".toCharArray(); char[] keypass = "wshr.ut".toCharArray(); String storename = "newstore"; context = SSLContext.getInstance("TLS"); kmf = KeyManagerFactory.getInstance("SunX509"); FileInputStream fin = new FileInputStream(storename); ks = KeyStore.getInstance("JKS"); ks.load(fin, storepass); kmf.init(ks, keypass); context.init(kmf.getKeyManagers(), null, null); SSLServerSocketFactory ssf = context.getServerSocketFactory(); ServerSocket ss = ssf.createServerSocket(5432); while (true) { Socket s = ss.accept(); PrintStream out = new PrintStream(s.getOutputStream()); out.println("Hi"); out.close(); s.close(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { int port = 37; ServerSocket server = new ServerSocket(port); while (true) { Socket connection = null; connection = server.accept(); OutputStream out = connection.getOutputStream(); out.write(123);/* w w w. j a va2 s. c om*/ out.flush(); connection.close(); } }
From source file:Main.java
public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(1234); while (true) { System.out.println("Listening"); Socket sock = ssock.accept(); DataOutputStream dstream = new DataOutputStream(sock.getOutputStream()); dstream.writeFloat(3.14159265f); dstream.close();/*from w w w. ja v a 2 s . c om*/ sock.close(); } }
From source file:MultiThreadServer.java
public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(1234); System.out.println("Listening"); while (true) { Socket sock = ssock.accept(); System.out.println("Connected"); new Thread(new MultiThreadServer(sock)).start(); }/*from ww w. j a va 2s . c om*/ }
From source file:GenericServer.java
public static void main(String args[]) { int serverPort = 1234; try {//from w ww . j a va 2s. c om ServerSocket server = new ServerSocket(serverPort); do { Socket client = server.accept(); (new ServerThread(client)).start(); } while (true); } catch (IOException ex) { System.exit(0); } }
From source file:Main.java
public static void main(String[] args) throws IOException { ServerSocket servsock = new ServerSocket(123456); File myFile = new File("s.pdf"); while (true) {//from ww w. j av a 2 s . c o m Socket sock = servsock.accept(); byte[] mybytearray = new byte[(int) myFile.length()]; BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myFile)); bis.read(mybytearray, 0, mybytearray.length); OutputStream os = sock.getOutputStream(); os.write(mybytearray, 0, mybytearray.length); os.flush(); sock.close(); } }