package com.sdc.callmaxent.socket; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; import com.sdc.callmaxent.util.FileUtil; import com.sdc.callmaxent.util.SocketUtil; import com.sdc.callmaxent.util.SystemConfig; public class CallMaxentClient { public static void main(String[] args){ try{ System.out.println("Start sending......"); String ipAddress = SystemConfig.getInstance().getIP(); int port = SystemConfig.getInstance().getPort(); Socket socket = SocketUtil.getSocket(ipAddress, port); BufferedReader bfReader = FileUtil.getBufferReader(new InputStreamReader(System.in)); System.out.println("Waiting....."); String strLine = "1,environmentallayers=F:/test/maxent/testdata/layers,samplesfile=F:/test/maxent/testdata/bradypus.csv,outputdirectory=F:/test/maxent/testdata/outputs,togglelayertype=ecoreg,redoifexists"; //String strLine = "environmentallayers=F:/test/maxent/testdata/layers,samplesfile=F:/test/maxent/testdata/bradypus.csv,outputdirectory=F:/test/maxent/testdata/outputs2,togglelayertype=ecoreg,redoifexists"; OutputStream outputStream = socket.getOutputStream(); InputStream inputStream = socket.getInputStream(); PrintWriter pw = new PrintWriter(outputStream,true); pw.println(strLine); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); System.out.println(br.readLine()); }catch (UnknownHostException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } } }
Java利用线程池实现处理Socket请求的小例子
内容版权声明:除非注明,否则皆为本站原创文章。