6
6713827
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
TForm1 = class(TForm)
CSocket: TClientSocket;
SSocket: TServerSocket;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Label2: TLabel;
Edit3: TEdit;
Edit4: TEdit;
Button3: TButton;
Button4: TButton;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure SSocketAccept(Sender: TObject; Socket: TCustomWinSocket);
procedure SSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure CSocketConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure CSocketDisconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure Button4Click(Sender: TObject);
procedure SSocketClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if button1.Caption='启动' then
begin
button1.caption:='停止';
ssocket.active:=true;
edit1.Text:='启动成功';
end
else
begin
button1.caption:='启动';
ssocket.Active:=false;
edit1.text:='停止成功';
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if button3.Caption='连接' then
begin
button3.caption:='断开';
csocket.active:=true;
end
else
begin
button3.caption:='连接';
csocket.active:=false;
end;
end;
procedure TForm1.SSocketAccept(Sender: TObject; Socket: TCustomWinSocket);
begin
edit1.text:='连接成功';
end;
procedure TForm1.SSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
edit1.text:='断开连接';
end;
procedure TForm1.CSocketConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
edit3.text:='连接成功';
end;
procedure TForm1.CSocketDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
edit3.text:='断开连接';
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
csocket.Socket.SendText(edit4.text);
end;
procedure TForm1.SSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo1.Lines.Add(socket.ReceiveText)
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ssocket.Socket.SendText(edit2.text);
end;
end.
连接OK,客户端向服务端发送数据OK,服务端向客户端发送数据有错误?
那为大侠能帮帮我啊.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
TForm1 = class(TForm)
CSocket: TClientSocket;
SSocket: TServerSocket;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Label2: TLabel;
Edit3: TEdit;
Edit4: TEdit;
Button3: TButton;
Button4: TButton;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure SSocketAccept(Sender: TObject; Socket: TCustomWinSocket);
procedure SSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure CSocketConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure CSocketDisconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure Button4Click(Sender: TObject);
procedure SSocketClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if button1.Caption='启动' then
begin
button1.caption:='停止';
ssocket.active:=true;
edit1.Text:='启动成功';
end
else
begin
button1.caption:='启动';
ssocket.Active:=false;
edit1.text:='停止成功';
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if button3.Caption='连接' then
begin
button3.caption:='断开';
csocket.active:=true;
end
else
begin
button3.caption:='连接';
csocket.active:=false;
end;
end;
procedure TForm1.SSocketAccept(Sender: TObject; Socket: TCustomWinSocket);
begin
edit1.text:='连接成功';
end;
procedure TForm1.SSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
edit1.text:='断开连接';
end;
procedure TForm1.CSocketConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
edit3.text:='连接成功';
end;
procedure TForm1.CSocketDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
edit3.text:='断开连接';
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
csocket.Socket.SendText(edit4.text);
end;
procedure TForm1.SSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo1.Lines.Add(socket.ReceiveText)
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ssocket.Socket.SendText(edit2.text);
end;
end.
连接OK,客户端向服务端发送数据OK,服务端向客户端发送数据有错误?
那为大侠能帮帮我啊.