免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: untrod
打印 上一主题 下一主题

有没有兴趣大家一起来做个聊天的系统 [复制链接]

论坛徽章:
0
51 [报告]
发表于 2008-07-17 16:33 |只看该作者

有点儿意思啦。

论坛徽章:
0
52 [报告]
发表于 2008-07-18 00:46 |只看该作者
好,做好了我拿来卖钱钱。。。

论坛徽章:
0
53 [报告]
发表于 2008-07-18 00:50 |只看该作者
没有我的参与,估计半年不会有什么进展。。。

论坛徽章:
0
54 [报告]
发表于 2008-07-18 16:43 |只看该作者
Flex的客户端



main.mxml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" backgroundColor="#AAAAAA">
  3.         <mx:Panel layout="absolute" left="10" right="10" top="10" bottom="10">
  4.                 <mx:TextArea id="mainText" top="10" left="10" right="10" bottom="40"/>
  5.                 <mx:TextInput id="msg" left="10" right="72" bottom="10"/>
  6.                 <mx:Button id="sendBtn" label="Send" right="10" bottom="10"/>
  7.         </mx:Panel>
  8.         <!--mx:Style source="assets/style.css" /-->
  9.         <mx:Script>
  10.                 <![CDATA[
  11.                 import flash.net.*;
  12.                 import mx.managers.PopUpManager;
  13.                 private const PORT:int = 4657;
  14.                 private const HOST:String = "61.129.51.204";
  15.                 private var svrMsg:String = "";
  16.                 private var clientSocket:Socket = new Socket;
  17.                 private var loginPanel:Login = new Login;
  18.                 private function init():void
  19.                 {
  20.                         this.msg.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
  21.                         this.sendBtn.addEventListener(MouseEvent.CLICK,onSend);
  22.                         this.clientSocket.addEventListener(Event.CONNECT,onConnect);
  23.                         this.clientSocket.addEventListener(Event.CLOSE,onClose);
  24.                         this.clientSocket.addEventListener(ProgressEvent.SOCKET_DATA,onData);
  25.                         PopUpManager.addPopUp(loginPanel,this,true);
  26.                         PopUpManager.centerPopUp(loginPanel);
  27.                         connectToServer();       
  28.                 }
  29.                 private function connectToServer():void
  30.                 {
  31.                         try{
  32.                                 this.clientSocket.connect(HOST,PORT);
  33.                         }catch(e:Error){
  34.                                 return;
  35.                                 //this.nativeApplication.exit(0);
  36.                         }
  37.                         this.clientSocket.writeMultiByte("<main_action>setNickName</main_action><nickname>"+loginPanel.nickName+"</nickname>","gb2312");
  38.                         this.clientSocket.flush();
  39.                 }
  40.                 private function onConnect(e:Event):void
  41.                 {
  42.                         svrMsg+="connect to server! \n";
  43.                         updateMsg();
  44.                 }
  45.                 private function onClose(e:Event):void
  46.                 {
  47.                         svrMsg+="connect close! \n";
  48.                         updateMsg();
  49.                 }
  50.                 private function onData(e:ProgressEvent):void
  51.                 {
  52.                         svrMsg+=this.clientSocket.readMultiByte(this.clientSocket.bytesAvailable,"gb2312")+"\n";
  53.                         updateMsg();
  54.                 }
  55.                 private function onSend(e:MouseEvent):void
  56.                 {
  57.                         send();
  58.                 }
  59.                 private function onKeyDown(e:KeyboardEvent):void
  60.                 {
  61.                         if(13==e.charCode)
  62.                         {
  63.                                 send();
  64.                         }
  65.                 }
  66.                 private function send():void
  67.                 {
  68.                         var temp:String = "<main_action>sendMsg</main_action><nickname>Alan</nickname><msg>"+this.msg.text+"</msg>"
  69.                        
  70.                         this.clientSocket.writeMultiByte(temp,"gb2312");
  71.                         this.clientSocket.flush();
  72.                         this.msg.text = "";
  73.                 }
  74.                 private function updateMsg():void
  75.                 {
  76.                         mainText.text = svrMsg;
  77.                 }
  78.                 ]]>
  79.         </mx:Script>
  80. </mx:Application>

复制代码


Login.mxml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="270" height="84" title="Input your name">
  3.         <mx:TextInput id="txt" x="10" y="12" keyDown="if(13==event.charCode)onClick();"/>
  4.         <mx:Button x="178" y="12" label="Button" click="onClick()"/>
  5.         <mx:Script>
  6.                 <![CDATA[
  7.                 import mx.managers.PopUpManager;
  8.                 public var nickName:String = "";
  9.                 private function onClick():void
  10.                 {
  11.                         PopUpManager.removePopUp(this);
  12.                         name = txt.text;
  13.                 }
  14.                 ]]>
  15.         </mx:Script>       
  16. </mx:TitleWindow>
复制代码



client.zip

276.51 KB, 下载次数: 54

源码和程序

论坛徽章:
0
55 [报告]
发表于 2008-07-18 16:51 |只看该作者
服务器没放跨域策略文件,网页上用这个会被安全沙箱挡住....大家想用还是下到本机用吧

http://kid.moker.com/img/Client.swf

[ 本帖最后由 alan_yang 于 2008-7-18 17:20 编辑 ]

论坛徽章:
0
56 [报告]
发表于 2008-07-24 17:09 |只看该作者
等,我加一个跨域文件吧

论坛徽章:
0
57 [报告]
发表于 2008-07-25 12:54 |只看该作者

回复 #19 untrod 的帖子

服务器支持我可以提供的 机器配置还不错的:)不过貌似不能24小时开放 可以么?

论坛徽章:
0
58 [报告]
发表于 2008-07-25 12:55 |只看该作者
有个可以24小时开放的 但是配置又不怎么好 只有512m的内存

论坛徽章:
0
59 [报告]
发表于 2008-07-25 13:56 |只看该作者
我有服务器,现在就是24小时开放

论坛徽章:
0
60 [报告]
发表于 2008-07-25 15:06 |只看该作者
看来真是人多力量大啊,新手关注中~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP