Unix环境C的Server,win2000 Delphi客户端,Socket连接问题(200分)

  • 主题发起人 主题发起人 china_hj
  • 开始时间 开始时间
C

china_hj

Unregistered / Unconfirmed
GUEST, unregistred user!
阻塞方式,使用ClientSocket1控件,与Server连接成功,可以发送字符,server端接受成功,但客户端始终不能Read到任何字符,因server是产品,不能看到源代码,只能在客户端寻找解决方案和思路,客户端使用方法如下:

ClientSocket1.Host := '192.168.0.6' ;
ClientSocket1.port := 6666 ;
try
if not ClientSocket1.Active then
ClientSocket1.Active := true ;
Except
showmessage('连接Socket失败');
end;
ClientSocket1.Socket.Lock ;
ClientSocket1.Socket.SendText(edit1.Text) ;
ClientSocket1.Socket.Unlock ;
SetLength(Buf_str,1000);
while clientSocket1.Socket.Connected do
begin
wsStream:=TWinSocketStream.Create(ClientSocket1.Socket,1000);
Fillchar(Buf_str,4,0);
if wsStream.WaitForData(1000) then
begin
if wsStream.Read(Buf_str,1)=0 then
ClientSocket1.Close;
end
else
ClientSocket1.Close;
wsStream.Free;
end;

for i:=0 to length(Buf_str)-1 do
str_s:=str_s+Buf_str;
showmessage(str_s);
ClientSocket1.Active:=False;

不吝赐教
 
用indy试试
IdTCPClient1. Connect;
IdTCPClient1.WriteStrings(edit1.Text);
IdTCPClient1.ReadString(s);
IdTCPClient1.Disconnect;
 
用clientSocket1已自行解决,自己没注意的小问题,和程序无关(说怎么找不到问题所在[:D])
还是感谢cash95的回答,
不过WriteStrings带的参数是Tstrings类型,可不是string 类型啊
readstring()是有返回值的,只跟参数S可不起作用啊
 
你的代码可以成功啊,我试过,是不是定义的地方有问题
ClientSocket1.Host := '192.168.0.6' ;
ClientSocket1.port := 6666 ;
ClientSocket1.Active := true ;
ClientSocket1.Socket.SendText('开始') ;
while ClientSocket1.Socket.Connected do
begin
wsStream1 := TWinSocketStream.Create(ClientSocket1.Socket,6000);
try
FillChar(Buffer, 10, 0);
if wsStream1.WaitForData(6000) then
begin
if wsStream1.Read(Buffer, 10) = 0 then
ClientSocket1.Close;
s_str := s_str + Buffer;
end
else
ClientSocket1.Close;
finally
wsStream1.Free;
end;
end;
showmessage(s_str);
 
接受答案了.
 
后退
顶部