Code example for ServerSocket

Methods: accept, close

0
		Socket socket = null;
		OutputStream output = null;
		InputStream input = null;
		int avali = 0;
		try { 
			s = new ServerSocket(PORT);
			System.out.println("ServerSocket Start:" + s);
			socket = s.accept();
			System.out.println("Connection accept socket:" + socket);
			output = socket.getOutputStream();
			input = new DataInputStream(socket.getInputStream());
			System.out.println(input.read());
			avali = input.available();
			System.out.println(avali);
		} catch (Exception e) {
			e.printStackTrace();
		} finally { 
			System.out.println("Close.....");
			try { 
 
				socket.close();
				s.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			} 
		} 
	}