Packagecn.rwkj.test;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.net.ServerSocket;ImportJava.net.Socket; Public classTestsocket {PrivateSocket sock=NULL ; Private StaticServerSocket Server =NULL; Private Static intport=8080 ; PublicTestsocket () {//Define a method Try{System.out.println (A); Server=NewServerSocket (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 blockE.printstacktrace (); } } Public Static voidMain (String []args) {NewTestsocket (); } PublicSocket Getsock () {returnsock; } Public voidSetsock (Socket sock) { This. Sock =sock; } PublicServerSocket getserver () {returnserver; } Public voidsetserver (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 soft Second Class MyEclipse blue==3