发新话题
打印

[Delphi] Delphi与FLASH通过SOCKET通信

Delphi与FLASH通过SOCKET通信

Delphi编写的服务器端代码(部分):

1procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
2Socket: TCustomWinSocket);
3begin
4 Form1.Memo1.Lines.Add(Socket.ReceiveText);
5 Form1.ServerSocket1.Socket.Connections[0].SendText('OK!'+#0);
6end;
7
8procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
9Socket: TCustomWinSocket);
10begin
11 Form1.Memo1.Lines.Clear;
12end;
13
14procedure TForm1.ServerSocket1Accept(Sender: TObject;
15  Socket: TCustomWinSocket);
16begin
17 Form1.Memo1.Lines.Clear;
18 Form1.Memo1.Lines.Add('Connected');
19 Form1.ServerSocket1.Socket.Connections[0].SendText('OK!'+#0);
20end;
21
22procedure TForm1.FormCreate(Sender: TObject);
23begin
24 Form1.ShockwaveFlash1.Movie:= ExtractFilePath(Application.Exename)+'client.swf';
25end;

Flash实现客户端代码(部分):

1var mySocket =
new XMLSocket();
2//
3mySocket.connect("127.0.0.1", 3000);
4mySocket.onConnect =
function(success) {
5    if (success) {
6        lists.text =
"Connect Ok!";
7        //mySocket.send("guest");
8        Selection.setFocus(input_txt);
9    }
else
{
10        lists.text =
"connect failed";
11    }
12};
13mySocket.onData =
function(s) {
14    lists.text+=s;
15};
16mySocket.onClose=function(){
17    lists.text+="Server has been closed.";
18}
19//
20bn_send.onRelease =
function() {
21    sendMsg(input_txt.text);   
22};
23function sendMsg(str) {
24    mySocket.send(str);
25    input_txt.text =
"";
26    Selection.setFocus(input_txt);
27}


[ 本帖最后由 Wayrt 于 2007-8-10 16:57 编辑 ]
九 九 教 院 毕 业 生,出 校 三 载 网 管 职,欲 写 病 毒 为 红 颜,谁 知 时 间 流 水 过,如 今 美 梦 影 成 空。

TOP

看看刘翔都为退出比赛说些什么

提示: 作者被禁止或删除 内容自动屏蔽

TOP

火影忍者

提示: 作者被禁止或删除 内容自动屏蔽

TOP

财政部公布2008年版安全生产专用设备企业所得税优惠目录

提示: 作者被禁止或删除 内容自动屏蔽

TOP

炊事班的故事3

提示: 作者被禁止或删除 内容自动屏蔽

TOP

新加坡移民

提示: 作者被禁止或删除 内容自动屏蔽

TOP

发新话题