这很简单:
程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, Menus, ExtCtrls, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
StatusBar1: TStatusBar;
Splitter1: TSplitter;
MainMenu1: TMainMenu;
listening: TMenuItem;
exit1: TMenuItem;
ServerSocket1: TServerSocket;
procedure listeningClick(Sender: TObject);
procedure ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure Memo1KeyPress(Sender: TObject; var Key: Char);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure exit1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.listeningClick(Sender: TObject);
begin
if listening.Checked
then
begin
listening.checked:=false;
serversocket1.active:=false;
statusbar1.simpletext:=' ';
end
else
begin
listening.checked:=true;
serversocket1.active:=true;
statusbar1.simpletext:='listening.... ';
end;
end;
procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.simpletext:='connected'+socket.remoteaddress;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo2.Lines.Append(socket.receivetext);
end;
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
if (key=#13) and (Serversocket1.Socket.activeconnections>0)
then
serversocket1.Socket.Connections[0].sendtext(memo1.lines[memo1.lines.count-1]);
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.simpletext:='listening....';
end;
procedure TForm1.exit1Click(Sender: TObject);
begin
close;
end;
end.
但这只是服务程序,还要一个客户程序。
夫子的上网要下网,下次告诉你客户程序,
你没 E-maill?