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;
不吝赐教
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;
不吝赐教