日期:2014-05-17 浏览次数:20657 次
import java.net.*; import java.io.*; public class Server{ private ServerSocket ss; private Socket socket; public Server(){ try{ ss = new ServerSocket(10000); socket = ss.accept(); System.out.println("Connection!"); } catch(IOException e){ System.err.println(e.toString()); } } public static void main(String args[]){ new Server(); } }
import javax.swing.*; import java.net.*; import java.io.*; public class Client extends JApplet{ private Socket socket; public void init(){ try{ socket = new Socket("127.0.0.1",10000); } catch(IOException e){ System.err.println(e.toString()); } } }
import javax.swing.*; import java.net.*; import java.io.*; public class Client extends JFrame{ private Socket socket; public Client(){ try{ socket = new Socket("127.0.0.1",10000); } catch(IOException e){ System.err.println(e.toString()); } setVisible(true); } public static void main(String args[]){ new Client(); } }