欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

socket客户端工具类

程序员文章站 2022-07-12 16:38:34
...
public String ConnectScoket(String host,int port,String xmlString ) throws IOException{
		Socket socket = new Socket(host, port);
		socket.setSoTimeout(10000);
		//流 输出流字符流
		OutputStream outs=socket.getOutputStream();
		System.out.println("发送的数据="+xmlString);
		outs.write(xmlString.getBytes("utf-8")); 
		outs.flush();
		//接收服务器返回数据
		InputStream ins=socket.getInputStream();
		BufferedReader reader=new BufferedReader(new InputStreamReader(ins));
	    String s=reader.readLine();
	    System.out.println("接到服务器回复:"+s);
	    socket.close();
	    return s;
	}
相关标签: socket