码迷,mamicode.com
首页 > 其他好文 > 详细

socket编程3-EchoServer

时间:2014-12-12 01:13:58      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:io   ar   os   sp   java   on   art   bs   ad   

package Chapter3;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class EchoServer {
    private ServerSocket server;
    private int port = 8000;
    private Socket socket;
    public EchoServer() {
        try {
            server = new ServerSocket(port);
        } catch (IOException e) {
            System.out.println("未启动ServerSocket");
        }
    }
public void service() {
    while(true){
        try {
        System.out.println("EchoServer等待客户端连接");
        socket=server.accept();
        Thread workThread=new Thread(new Handler(socket));
        workThread.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
    }
}
    public static void main(String[] args) {
        new EchoServer().service();
    }

}

socket编程3-EchoServer

标签:io   ar   os   sp   java   on   art   bs   ad   

原文地址:http://www.cnblogs.com/stay-sober/p/4158800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!