clientsocket组件的使用?

eliuren 2003-09-20 05:06:45
请问clientsocket可以设置网络连接超时吗?怎么设置,最好能贴段原码?非常感谢!
...全文
72 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wally_wu 2003-10-22
  • 打赏
  • 举报
回复
if not CheckSocketAvail then
raise Exception.Create('Remote connection not available');
邹工 2003-10-01
  • 打赏
  • 举报
回复
procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);

begin
// TErrorEvent = (eeGeneral, eeSend, eeReceive,
// eeConnect, eeDisconnect, eeAccept, eeLookup);
case ErrorEvent of
eeGeneral:memo1.Lines.Add('eeGeneral');
eeSend:memo1.Lines.Add('eeSend');
eeReceive:memo1.Lines.Add('eeReceive');
eeConnect:memo1.Lines.Add('连接超时[eeConnect]');
eeDisconnect:memo1.Lines.Add('eeDisconnect');
eeAccept:memo1.Lines.Add('eeAccept');
eeLookup:memo1.Lines.Add('eeLookup');
end;

errorCode:=0;
end;
2312 2003-09-28
  • 打赏
  • 举报
回复
还是给你贴处理吧


procedure TF_main.Timer1Timer(Sender: TObject);
begin
if not ClientSocket1.Active then
begin
clientsocket1.Host:=strseraddr;
ClientSocket1.Active:=true;
ClientSocket1.Socket.Lock;
end
else
begin
ClientSocket1.Socket.SendText(strSockType+','+strIP+','+strSockValue+',');
Timer1.Enabled:=false;
end;
end;

procedure TF_main.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
try
if errorcode=0
then
begin
..........
end;
except
....
end;
end;
2312 2003-09-28
  • 打赏
  • 举报
回复
我是这样做的:
连接写到Timer1里面,用OnError 事件中的try..except..配合使用,这样就不会死机了


你可以用Timer计时,超过一定时间就是超时,而在这段时间里你可以反复连接,也包括异常处理
XXSingle 2003-09-28
  • 打赏
  • 举报
回复
目前我也只用OnError 事件中的try..except..慢是慢了点,
不过至少程序不会死...
eliuren 2003-09-28
  • 打赏
  • 举报
回复
to FSU(洋葱面) :这样太慢了
FSU 2003-09-27
  • 打赏
  • 举报
回复
通过OnError 事件,用try..except..
eliuren 2003-09-26
  • 打赏
  • 举报
回复
郁闷
hiflower 2003-09-24
  • 打赏
  • 举报
回复
Specifies whether the client socket reads and writes information asynchronously over the socket connection.

type TClientType = (ctNonBlocking, ctBlocking);
property ClientType: TClientType;

Description

Set ClientType to ctNonBlocking to enable the client socket to respond to asynchronous reading and writing events. When ClientType is ctNonBlocking, execution is not blocked by reading and writing over the socket connection. OnRead or OnWrite events occur when the socket needs to read or write over the connection.

Set ClientType to ctBlocking to force all reading and writing to occur synchronously. It is a good idea to include the client socket object in a thread if the ClientType is ctBlocking, so that I/O does not block all execution within the client application.

When ClientType is ctBlocking, use a TWinSocketStream object for reading and writing. TWinSocketStream prevents the application from hanging indefinitely if a problem occurs while reading or writing. It also can wait for the socket connection to indicate its readiness for reading.

Use a non-blocking socket when the socket needs to synchronize reading and writing with server sockets.
eliuren 2003-09-24
  • 打赏
  • 举报
回复
怎么没人回答?
killme2008 2003-09-24
  • 打赏
  • 举报
回复
楼上的楼上能不能翻译一下
eliuren 2003-09-24
  • 打赏
  • 举报
回复
看不懂
eliuren 2003-09-22
  • 打赏
  • 举报
回复
to hiflower(花) :那样处理的话,如果一但服务器端断开或网络连接异常的话,程序运行很慢,几乎会死掉
to halfdream(哈欠) :我用的是阻塞式的,说说你的处理方法,最好帖出原代码!

谢谢各位!
halfdream 2003-09-21
  • 打赏
  • 举报
回复
如果你使用非阻塞方式,你可以OPEN后在一定时间内如果无OnConnected,
则是连接超时.

如果是阻塞方式,超时处理较麻烦一些..
hiflower 2003-09-21
  • 打赏
  • 举报
回复
不行吧,只能通过 OnError 事件来捕捉
bitcom 2003-09-21
  • 打赏
  • 举报
回复
没试过,看看帮助!!!
eliuren 2003-09-21
  • 打赏
  • 举报
回复
郁闷,哪为高手帮帮我!
zhhuang2002 2003-09-20
  • 打赏
  • 举报
回复
好象不能设置

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧