少林

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
import java.io.*;
import java.net.*;

public class ClientTest {
    public static void main(String[] args) throws Exception {
        Socket s = new Socket("localhost", 8888);
        DataOutputStream dos = new DataOutputStream(s.getOutputStream());
        dos.writeUTF("client:hello");
        DataInputStream dis = new DataInputStream(s.getInputStream());
        System.out.println(dis.readUTF());
        
        //s.close();
    }
}
import java.io.*;
import java.net.*;
import java.net.ServerSocket;

public class ServerTest {
    public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(8888);
        Socket s = ss.accept();
        
        DataOutputStream dos = new DataOutputStream(s.getOutputStream());
        dos.writeUTF("server: hi, I am server !");
        DataInputStream dis = new DataInputStream(s.getInputStream());
        
        System.out.println(dis.readUTF());
        //s.close();
    }
}

 

posted on 2015-07-20 15:34  Stanley_yu  阅读(244)  评论(0编辑  收藏  举报