我的server怎么不能发信息到client???dx们可以帮我解释一下套接字吗?(20分)

  • 主题发起人 主题发起人 ybbh
  • 开始时间 开始时间
Y

ybbh

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(][:(]
服务器端
procedure TForm1.Button1Click(Sender: TObject);
begin
if button1.caption='启动' then
begin
serversocket1.Port :=strtoint(edit2.Text);
serversocket1.Active :=true;
button1.Caption :='停止';
end
else
if button1.Caption='停止' then
begin
serversocket1.Active:=false;
button1.Caption :='启动';
end


end;

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
label1.Caption :='用户连接成功 ';
end;

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
label1.Caption :='用户连接中断 ';
end;

procedure TForm1.ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
label1.Caption := '连接错误 ';
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var shuru:string;

begin

shuru:=socket.ReceiveText;
memo1.Lines.Add(shuru);
meini:=Tinifile.Create(extractfilepath(application.exename)+'log.txt');
meini.WriteString('log',inttostr(n),shuru);
n:=n+1;

if shuru='user' then
begin
memo1.Lines.add('成功收到字符(user)');
//ccss[1]:=socket;
serversocket1.Socket.Connections[0].SendText('1111')
//Socket.SendText('1111');
end
end;

procedure TForm1.ServerSocket1Listen(Sender: TObject;
Socket: TCustomWinSocket);
begin
label1.Caption :='正在监听 ';

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.text:='';
end;
客户端
procedure TForm1.Button1Click(Sender: TObject);
var kao:string;
begin

clientsocket1.Address :=edit2.Text ;
clientsocket1.Port :=strtoint(edit1.Text);
clientsocket1.Active :=true;
showmessage('好象连上了呀');
kao:=clientsocket1.Socket.ReceiveText;
if kao='1111' then
begin
showmessage('日!终于收到了');
end

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
clientsocket1.Socket.SendText(memo1.Text);
memo1.Text :='';
if clientsocket1.Socket.ReceiveText='pass' then

end;

procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
memo2.Lines.add('连接错误');
end;
 
就是这里,套接字怎么样呢

memo1.Lines.add('成功收到字符(user)');
//ccss[1]:=socket;
serversocket1.Socket.Connections[0].SendText('1111')
//Socket.SendText('1111');
 
1.你应该把接收服务段发送的数据的代码放在TClientSocket的OnRead Event中,
procedure TForm1.ClientRead(Sender: TObject; Socket: TCustomWinSocket);
var kao:string;
begin
kao:=Socket.ReceiveText;
if kao='1111' then
begin
showmessage('日!终于收到了');
end
end;

2.找tcp/ip和winsock编程方面的书
 
谢谢了 不好意思 好久没有上网了
 
后退
顶部