- import java.net.ServerSocket;
- import java.net.Socket;
- public class SeverSocketDemo {
- public static void main(String[] args)throws Exception
- {
- ServerSocket ss = new ServerSocket(8008); //创建一个服务型ServerSocket
- Socket s =ss.accept(); //调用ServerSocket的accept()方法获得连接到ServerSocket的Socket实例对象
- s.getOutputStream(); //通过获取到的Socket对象来取得输出流和输入流进行数据传输,
- s.getInputStream();
- }
- }
复制代码
|