flex和delphi做的服务器进行通讯

本文介绍了一种使用Flex进行前台页面设计,而后台采用Delphi通过Socket处理数据的通信方式。具体展示了如何利用Delphi的Indy库实现TCP服务器,并与Flex客户端建立连接,进行数据读取和日志记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用flex做前台页面,后台使用delphi处理数据,之间用socket连接。。。delphi使用indy的tcpserver。的确很好玩。哈哈。可以不知道那些网页游戏是否是这样做成的。。。先贴个效果图,再贴代码。。很简单的说。

服务端代码:


unit  uMain;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdUDPBase, IdUDPServer, IdBaseComponent, IdComponent,
IdTCPServer;

type
TfFlexServerTest 
=   class (TForm)
    Memo1: TMemo;
    Button1: TButton;
    IdTCPServer1: TIdTCPServer;
    
procedure  IdTCPServer1Connect(AThread: TIdPeerThread);
    
procedure  IdTCPServer1Execute(AThread: TIdPeerThread);
    
procedure  IdTCPServer1Disconnect(AThread: TIdPeerThread);
    
procedure  log(logInfo: string );
private
    
{  Private declarations  }
public
    
{  Public declarations  }
end ;

var
fFlexServerTest: TfFlexServerTest;

implementation

{ $R *.dfm }
procedure  TfFlexServerTest.log(logInfo: string );
begin
Memo1.Lines.Add(logInfo);
end ;
procedure  TfFlexServerTest.IdTCPServer1Connect(AThread: TIdPeerThread);
begin
log(
' 有人来连接 ' );
end ;

procedure  TfFlexServerTest.IdTCPServer1Execute(AThread: TIdPeerThread);
var
s:
string ;
begin
s:
= AThread.Connection.ReadLn;
s:
= UTF8Decode(s);
log(s);
end ;

procedure  TfFlexServerTest.IdTCPServer1Disconnect(AThread: TIdPeerThread);
begin
log(
' 有人离开 ' );
end ;

end .

客户端代码:

<? xml version="1.0" encoding="utf-8" ?>
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"  layout ="absolute"  backgroundGradientAlphas ="[1.0, 1.0]"  backgroundGradientColors ="[#000000, #FFFFFF]"  creationComplete ="initApp()" >
< mx:Script >
<![CDATA[
   import flash.net.Socket;
   import flash.events.MouseEvent;
   private var YTsocket:Socket=new Socket();
  
   internal function initApp():void
   {
    YTsocket.connect("127.0.0.1",1985);
    btn1.addEventListener(MouseEvent.CLICK,onClick);
   }
   internal function onClick(event:MouseEvent):void
   {
    var msg:ByteArray=new ByteArray();
    msg.writeUTFBytes(txt.text+"\n");
    //YTsocket.writeBytes(msg);
    YTsocket.writeUTFBytes(msg+"\n");
    YTsocket.flush();
   }
]]>
</ mx:Script >
< mx:Panel  width ="250"  height ="200"  layout ="absolute"  title ="消息发送方"  fontSize ="15"  backgroundAlpha ="0.15"  alpha ="1.0"  horizontalCenter ="-11"  verticalCenter ="5" >
   
< mx:Button  x ="82"  y ="111"  label ="发送"  id ="btn1"  fontSize ="13" />
   
< mx:TextArea  height ="72"  id ="txt"  horizontalCenter ="0"  verticalCenter ="-31"  color ="#FA040A" />
</ mx:Panel >

</ mx:Application >

 

转载于:https://www.cnblogs.com/OneSpeak/articles/1527295.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值