Code example for Socket

Methods: getInputStream, getOutputStream, isConnected

0
			return false; 
		} 
		 
		 
		// try opening socket even if it's not null. 
		if (socket.isConnected() != true) {
			openSocket(); 
		} 
 
		// Is the socket open? 
		if (socket.isConnected() != true) {
			if (DEBUG) msg("After opening socket, it was not connected.");
			return false; 
		} 
 
		if (DEBUG) msg("Successfully opened socket.");
		return true; 
	} 
 
	/** 
	 * Perform an internet based TCPIP lookup by sending the DTC to the GTO 
	 * server and getting the response description. 
	 *  
	 * @param DTC 
	 * @return 
	 */ 
	private String getServerDTCDescription(String DTC) {
		String description = "";
		String prefix = "GET /dtc/index.php?DTC=";
		String suffix = "&auth=" + mClientID;
 
		// make sure we're connected. 
		if (getOpenSocket() != true) 
			return ""; 
 
		// Set up output stream 
		PrintWriter out;
		try { 
			out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
		} catch (Exception e) {
			msg("Error attaching output stream: " + e.getMessage());
			return ""; 
		} 
 
		// set up input stream. 
		BufferedInputStream inStream = null;
		try { 
			inStream = new BufferedInputStream(socket.getInputStream());
		} catch (Exception e) {
			msg("Error attaching input stream: " + e.getMessage());
			return ""; 
		}