使用RECV接收部分数据包 [英] Receiving partial Packets using RECV

查看:260
本文介绍了使用RECV接收部分数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我已经编写了一段代码,但是无法正常工作

Hello,

I have made myself a piece of code, but it is not working correctly

$socket->send($sPacket);
($msg) = '';
recv($socket, $msg, 10, 0) or die "recv: $!"; #This line
if($msg != NULL)
{
    recv($socket, $msg2, 5, 0) or die "recv: $!"; #This line
    if($msg2 == 'p4150')
    {
        print "Successfully connected to the server.";
    }
    else
    {
        print "FAILB : $msg2";
    }
}
else
{
    print "FAILA : $msg";
}



这是行不通的,因为RECV(带有标志0)希望有一个至少具有接收数据包大小的缓冲区.数据包的长度为15,我只希望前10位,然后第二个RECV上的后5位.
我可以使用任何标志来解决此问题,还是有一个好的选择(其他接收功能/其他功能)?

提前谢谢!,
Tim



It doesn''t work because RECV(with flags 0) wants be to have a buffer of at least the size of the receiving packet. The packet has a length of 15 , I want only the first 10 bits and then the next 5 on the second RECV.
Are there any flags I can use to solve this problem, or is there a good alternative (other receiving function/something else)?

Thanks in advance!,
Tim

推荐答案

socket -> send(
socket->send(


sPacket ); (
sPacket); (


msg )= '
msg) = ''; recv(


这篇关于使用RECV接收部分数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆