Packagecn.rwkj.test;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.OutputStream;ImportJava.io.PrintWriter;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); OutputStream out=Sock.getoutputstream (); PrintWriter Write=NewPrintWriter (out); Write.println ("Http/1.0.200 OK"); Write.println ("Content-type:/html; CHARSET:GBK "); Write.println (); write.println( "<div style= ' width:300px; height:300px; Background: #FF0000 ' > Asdfasdf </div> "); Write.close (); } 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; } PublicString getString (InputStream in)throwsioexception{String str=""; byte[] b=New byte[1024]; intLen=-1; while(len = In.read (b))!=-1) {System.out.println (len); STR=NewString (b); Break; } returnstr; }}
2014--9=17 soft Second Class MyEclipse blue==5