在python中读取big-endian UDP数据包

时间:2018-06-21 01:50:34

标签: python matlab sockets udp decode

我有一个工作的Matlab代码,用于udp数据包读取,我想将其翻译为Python。通常,我正在做类似的事情:

@using (Ajax.BeginForm("GetTrackAppearanceCount", "CustomQuery", new AjaxOptions
{

    UpdateTargetId = "contentArea",
    LoadingElementId = "loadingDiv",
    OnFailure = "AjaxFailure",
    OnBegin = "AjaxBegin",
    OnComplete = "AjaxComplete"

}, new { @class = "form-inline" }))
{
    <div class="row">
        <div>
            <h4>How many songs appear with the given track title</h4>
            <div class="form-group">
                <input id="songTitle" name="songTitle" type="text" class="form-control" placeholder="Please Enter Track Title" />
                <input type="submit" class="btn" value="search" />
            </div>
        </div>

    </div>

}

这一次,解码似乎无法正常进行。在Matlab代码中,正在使用pnet读取数据包:

try:
    sock.settimeout(timeout)
    next_val = sock.recv(2048)
except socket.timeout as e:
    print('!!! timed out !!!')
else:
    next_val = next_val.decode(sys.getfilesystemencoding(), 'ignore')

如何在Python中指定解码是大端的?我尝试使用numpy:

next_val = pnet(socket,'read',packetSize,dtype,'intel');

但是它似乎不起作用。 有什么建议么? 谢谢!

0 个答案:

没有答案