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}

源文件下载