Code example for DataInputStream

Methods: readUTFclose

0
		try { 
			socket = new Socket("127.0.0.1", 8080);
			// 向服务器端第一次发送字符串 
			OutputStream netOut = socket.getOutputStream();
			DataOutputStream doc = new DataOutputStream(netOut);
			DataInputStream in = new DataInputStream(socket.getInputStream());
			// 向服务器端第二次发送字符串 
			doc.writeUTF("list");
			String res = in.readUTF();
			System.out.println(res);
			doc.writeUTF("bye");
			res = in.readUTF();
			System.out.println(res);
			doc.close();
			in.close();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally { 
Stop searching for code, let great code find you!  Add Codota to your java IDE