Code example for Socket

Methods: close, getInputStream, getOutputStream, shutdownInput, shutdownOutput

0
	public void connect(String host, int port) throws IOException {
		if (debug > 0)
			System.err.println("Wrapper: connect(" + host + "," + port + ")");
		try { 
			this.host = host;
			socket = new java.net.Socket(host, port);
			in = socket.getInputStream();
			out = socket.getOutputStream();
		} catch (Exception e) {
			System.err.println("Wrapper: " + e);
			disconnect(); 
			throw ((IOException) e);
		} 
	} 
 
	/** Disconnect the socket and close the connection. */ 
	public void disconnect() throws IOException { 
		if (debug > 0)
			System.err.println("Wrapper: disconnect()");
		 
		/* we need to shut down io or close() will wait for it */ 
		socket.shutdownInput();
		socket.shutdownOutput();
		socket.close();		
	} 
 
	/** 
	 * Login into remote host. This is a convenience method and only works if 
	 * the prompts are "login:" and "Password:".