- 论坛徽章:
- 0
|
问题已经困扰我有一段时间了,在公司进行测试的时候程序能正常运行,但是一放到服务器上(linux),程序运行后,服务端就报收不到消息。我写的是客户端。但是用java的测试程序服务端又能收到。
下面我贴下发送消息的那块代码,大家看看是什么问题
# 发送消息方法
sub sendConnStr{
my ($CliSocket,$strConnectString,$strPassword) = @_;
my $lencon = length($strConnectString);
my $lenpaw = length($strPassword);
while($lencon>0){
my $relen = syswrite($CliSocket,$strConnectString,$lencon);
#$CliSocket->flush();
$lencon = $lencon-$relen;
unless($relen){
$logState->setState(State->STATE_STOP,"发送连接字符失败,程序退出");
print STDERR getLongTime()." 发送连接字符失败,程序退出!\n";
exit;
}
}
while($lenpaw>0){
my $relen = syswrite($CliSocket, $strPassword ,$lenpaw);
# $CliSocket->flush();
$lenpaw = $lenpaw-$relen;
unless($relen){
$logState->setState(State->STATE_STOP,"发送连接密码失败,程序退出");
print STDERR getLongTime()." 发送连接密码失败,程序退出!\n";
exit;
}
}
#建立socket连接
if ( $ReconEveryDay) {
$socketcnt=0;
vec($rin, fileno($CliSocket), 1) = 0;
do {
sleep(3);
$CliSocket->close() if $CliSocket;
$CliSocket = IO::Socket::INET->new('PeerAddr' => $var{IpAddress},
'PeerPort' => $var{IpPort},
'Proto' => $Proto);
unless($CliSocket){
if($socketcnt>10){
$logState->setState(State->STATE_STOP,"每日重连socket时连接次数超过10次,程序退出");
print STDERR getLongTime()." 每日重连socket时连接次数超过10次,程序退出,让监控程序重起该程序!\r\n";
exit;
}
$logState->setState(State->STATE_ERROR,"每日重新连接socket ".$var{ServerName}." 失败");
print STDERR getLongTime()." 每日重新连接socket ".$var{ServerName}." 失败!\r\n";
$socketcnt ++;
}
} until ($CliSocket);
$socketcnt=0;
#$CliSocket->autoflush(1);
$logState->setState(State->STATE_TRACE,"每日重新连接socket ".$var{ServerName}." 成功");
print getLongTime()." 每日重新连接socket ".$var{ServerName}." 成功!\r\n";
#调用发送消息方法
sendConnStr($CliSocket,$sendAlarmAck); #发送连接状态回复信息 |
|