TCP / IP服务器 - 客户端是否有数据发送限制?

时间:2015-08-21 00:46:43

标签: python swift sockets tcp-ip

我写的数字在100-255之间,以控制我的减速电机的速度。 (100以下运行困难)。

在我的UDOO上,我正在运行用python编写的TCP / IP Server代码。它绑定服务器地址,然后侦听并接受来自客户端的连接。 它执行一个while循环,从TCP / IP客户端(我的iPhone)接收数据,然后打印并将其(连续)写入我的UDOO上的Arduino芯片。 编辑:这是完整的Python服务器代码

import socket
import sys
import serial

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server_address = ('IP', 10000)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
sock.listen(1)

print >>sys.stderr, 'waiting for a connection...'
connection, client_address = sock.accept()
print >>sys.stderr, 'connection from', client_address
while True:
    data = connection.recv(16)
    print >>sys.stderr, 'received "%s"' % data
    ser.write(data)

我的iPhone上的swift代码正在使用此命令连接到同一个IP python代码连接到。

NSStream.getStreamsToHostWithName()

使用

将加速度计数据写入输出流

outputStream.write(string,maxLength:count(string))

如果我将iPhone向右倾斜,则减速电机的速度会增加。

当accelerometerUpdateInterval = 1时,减速电机的速度会以1秒的延迟变化。 python服务器代码每秒接收1个数据包,没有传输错误。显示的数字介于100到255之间。

如果我将加速度计的更新间隔设置为0.01,则python代码每秒接收100个数据包。显示的数字示例如下:

received "198"
received "184"
received "179"
received "196"
received "204"
received "2061991871851851"
received "8217717417718118"
received "5185176169184187"
received "1811401761961901"
received "6213912912712612"
received "2118115114105"
received "1051051001001001"
received "0010010110110110"
received "1101101101101101"
received "1011011011011011"
received "0110110110110110"
received "1101101101101101"
received "1011011011011011"
received "0110110110110110"
received "1"
received "1011011011011011"
received "0110110110110110"
received "1101101101101101"
received "101101"
received "101"
received "101"
received "101"

像198,184,179这样的数字是准确的并且正确传输,因为这是我持有iPhone的角度。其他大于3位或大于255的数字不应该出现,并且swift代码没有被编程来创建它们,当它每秒接收100个数据包时,TCP / IP传输一定存在问题。

当更新间隔为0.1时,仍然存在一些问题,但频率较低。

1 个答案:

答案 0 :(得分:0)

  

像198,184,179这样的数字是准确无误的   因为那是我拿着我的iPhone的角度而传播的。该   不应该使用大于3位或超过255的其他数字   显示并且没有编写快速代码来创建它们   当收到100时,TCP / IP传输必须是一个问题   每秒数据包。

毕竟,也许这些数字确实有意义。我只是添加了空格来表达观点:

received "206 199 187 185 185 1"
received "82 177 174 177 181 18"
received "5 185 176 169 184 187"
received "181 140 176 196 190 1"