Delphi編寫的服務(wù)器端代碼(部分):
源文件下載
1
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
2
Socket: TCustomWinSocket);
3
begin
4
Form1.Memo1.Lines.Add(Socket.ReceiveText);
5
Form1.ServerSocket1.Socket.Connections[0].SendText('OK!'+#0);
6
end;
7
8
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
9
Socket: TCustomWinSocket);
10
begin
11
Form1.Memo1.Lines.Clear;
12
end;
13
14
procedure TForm1.ServerSocket1Accept(Sender: TObject;
15
Socket: TCustomWinSocket);
16
begin
17
Form1.Memo1.Lines.Clear;
18
Form1.Memo1.Lines.Add('Connected');
19
Form1.ServerSocket1.Socket.Connections[0].SendText('OK!'+#0);
20
end;
21
22
procedure TForm1.FormCreate(Sender: TObject);
23
begin
24
Form1.ShockwaveFlash1.Movie:= ExtractFilePath(Application.Exename)+'client.swf';
25
end;
Flash實(shí)現(xiàn)客戶端代碼(部分):
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

1
var mySocket = new XMLSocket();
2
//
3
mySocket.connect("127.0.0.1", 3000);
4
mySocket.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
};
13
mySocket.onData = function(s)
{
14
lists.text+=s;
15
};
16
mySocket.onClose=function()
{
17
lists.text+="Server has been closed.";
18
}
19
//
20
bn_send.onRelease = function()
{
21
sendMsg(input_txt.text);
22
};
23
function sendMsg(str)
{
24
mySocket.send(str);
25
input_txt.text = "";
26
Selection.setFocus(input_txt);
27
}

2

3

4



5



6

7

8

9



10

11

12

13



14

15

16



17

18

19

20



21

22

23



24

25

26

27

源文件下載