connect to socket server

	/**
	 * Connect socket server to return data interface method
	 * @param host IP
	 * @param port port number
	 * @param xmlString push data string
	 * @return String returns the data string
	 * @throws IOException
	 */
	public String ConnectScoket(String host,int port,String xmlString ) throws IOException{
		Socket socket = new Socket(host, port);
		socket.setSoTimeout(10000);
		// stream output stream character stream
		OutputStream outs=socket.getOutputStream();
		System.out.println("Sent data="+xmlString);
		outs.write(xmlString.getBytes("utf-8"));
		outs.flush();
		//Receive the data returned by the server
		InputStream ins=socket.getInputStream();
		BufferedReader reader=new BufferedReader(new InputStreamReader(ins));
	    String s=reader.readLine();
	    System.out.println("Received server reply: "+s);
	    socket.close();
	    return s;
	}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326170158&siteId=291194637