M
michen
Unregistered / Unconfirmed
GUEST, unregistred user!
--------------------------------------------------------------
首先想问一下哪位高手有indy的tcpclient的教程,说明之类的资料,
当然最好是中文的,有例子就更好了
--------------------------------------------------------------
下面是一段perl的程序,用一个无限循环来读socket数据,
问题是dataWaiting这段子程序偶看不懂,哪位高手能讲解一下?
在delphi中如何实现这段?
首先想问一下哪位高手有indy的tcpclient的教程,说明之类的资料,
当然最好是中文的,有例子就更好了
--------------------------------------------------------------
下面是一段perl的程序,用一个无限循环来读socket数据,
问题是dataWaiting这段子程序偶看不懂,哪位高手能讲解一下?
在delphi中如何实现这段?
代码:
$remote_socket = IO::Socket::INET->new();
$server_socket = IO::Socket::INET->new(
Listen => 5,
LocalAddr => $config{'local_host'},
LocalPort => $config{'local_port'},
Proto => 'tcp',
Timeout => 2,
Reuse => 1);
($server_socket) || die "Error creating local server: $!";
while ($quit != 1) {
usleep($config{'sleepTime'});
if (dataWaiting(/$input_socket)) {
$stop = 1;
$input_socket->recv($input, $MAX_READ);
parseInput($input);
} elsif (dataWaiting(/$remote_socket)) {
$remote_socket->recv($new, $MAX_READ);
$msg .= $new;
$msg_length = length($msg);
while ($msg ne "") {
$msg = parseMsg($msg);
last if ($msg_length == length($msg));
$msg_length = length($msg);
}
}
$ai_cmdQue_shift = 0;
do {
AI(/%{$ai_cmdQue[$ai_cmdQue_shift]}) if ($conState == 5 && timeOut(/%{$timeout{'ai'}}) && $remote_socket && $remote_socket->connected());
undef %{$ai_cmdQue[$ai_cmdQue_shift++]};
$ai_cmdQue-- if ($ai_cmdQue > 0);
} while ($ai_cmdQue > 0);
checkConnection();
}
sub dataWaiting {
my $r_fh = shift;
my $bits;
vec($bits,fileno($$r_fh),1)=1;
return (select($bits,$bits,$bits,0.05) > 1);
}