分类:
2008-09-09 13:26:07
try{ boolean flag=true; Socket clientSocket=null; ServerSocket serverSocket = new ServerSocket(0); System.out.println("Server listen on: " +serverSocket.getLocalPort()); while(flag){ clientSocket=serverSocket.accept(); DataInputStream is=new DataInputStream( new bufferedInputStream(client Socket.getInputStream())); PrintStream os=new PrintStream( new bufferedOutputStream(clientSocket. getOutputStream())); // 处理Applet请求 os.close(); is.close(); clientSocket.close(); } serverSocket.close(); }catch( IOException e){ System.err.println(" Exception: "+e); } |
try { Socket clientSocket =new Socket("serverName",7); OutputStream os=clientSocket.getOutputStream(); DataInputStream is=new DataInputStream( clientSocket.getInputStream()) ; // 其它操作. os.close(); is.close(); clientSocket.close(); }catch(Exception e){ System.err.println("Exception:"+e); } |