首页 > 代码库 > 2014--9=17 软工二班 MyEclipse blue==3
2014--9=17 软工二班 MyEclipse blue==3
package cn.rwkj.test;import java.io.IOException;import java.io.InputStream;import java.net.ServerSocket;import java.net.Socket;public class TestSocket { private Socket sock=null ; private static ServerSocket server =null; private static int port=8080 ; public TestSocket() { //定义一个方法 try { System.out.println("a"); server=new ServerSocket(port); server.accept(); System.out.println("ip:" + sock.getInetAddress()); InputStream in = sock.getInputStream(); String str = getString(in); System.out.println(str); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String []args){ new TestSocket(); } public Socket getSock() { return sock; } public void setSock(Socket sock) { this.sock = sock; } public ServerSocket getServer() { return server; } public void setServer(ServerSocket server) { this.server = server; } public String getString(InputStream in) throws IOException{ String str=""; byte [] b=new byte[1024]; int len=-1; while( (len = in.read(b) )!=-1 ) { System.out.println(len); str = new String(b) ; break; } return str; }}
2014--9=17 软工二班 MyEclipse blue==3
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。