找回密码
 入驻
搜索
查看: 423|回复: 7

java程序设计@

[复制链接]
发表于 2010-3-27 20:13:36 | 显示全部楼层 |阅读模式
服务端代码:
import java.net.*;
import java.io.*;
public class ChatServer {
          

        public static void main(String[] args) {
                boolean started = false;
                ServerSocket ss = null;
                Socket s = null;
                DataInputStream dis =null;
                try{
                        ss = new ServerSocket(8888);
                }catch(BindException e){
                        System.out.println("端口被占用中.....");
                        System.out.println("请关掉相关服务器");
                        System.exit(0);
                }catch(IOException e) {
                        e.printStackTrace();
                }
                try{
                        started = true;
                        while(started) {
                                boolean bconnect = false;
                               
                                        s = ss.accept();
                                        bconnect = true;
                                        System.out.println("a clint connected!");
                                        dis = new DataInputStream(s.getInputStream());
                                        while(bconnect) {
                                               
                                                String str = dis.readUTF();
                                                System.out.println(str);
                                }
                                //dis.close();
                        }
                }catch(EOFException e) {
                        System.out.println("客户端退出");
                }catch(IOException e) {
                        e.printStackTrace();
                }finally{
                        try {
                                if(dis != null) dis.close();
                                if(s != null) s.close();
                        } catch (IOException e) {
                       
                                e.printStackTrace();
                        }
                }
        }

}
发表于 2010-3-27 20:21:11 | 显示全部楼层
童鞋,你干什么!
回复

使用道具 举报

发表于 2010-3-27 20:56:45 | 显示全部楼层
你有什么不能一次性发完吗? = =
回复

使用道具 举报

发表于 2010-3-27 22:15:03 | 显示全部楼层
路过、、、、、学C#的,看不得JAVA的东西
回复

使用道具 举报

发表于 2010-3-27 22:30:47 | 显示全部楼层
同楼上~~~~
回复

使用道具 举报

发表于 2010-3-28 09:50:55 | 显示全部楼层
沙发
回复

使用道具 举报

发表于 2010-3-28 09:51:21 | 显示全部楼层
什么都看不懂
回复

使用道具 举报

发表于 2010-6-15 12:28:12 | 显示全部楼层

同楼上,什么都看不懂。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 入驻

本版积分规则

QQ|Archiver|手机版|小黑屋|思明论坛

GMT+8, 2024-5-3 04:10 , Processed in 0.061310 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表