在接口级别DCCP就像TCP:你连接然后发送/接收字节。
我想知道通过调整tcp的包装器可以使dccp连接成为扭曲...
根据示例代码(如下),需要更改的内容是:
然后其他一切都会一样......
提示:我在扭曲的来源中发现了addressFamily
和socketType
,但我不知道如何在协议工厂中干净地设置它们。协议号,第三个参数,这里IPPROTO_DCCP
,总是保持默认值。我不知道如何访问套接字以调用setsockopt
import socket
socket.DCCP_SOCKOPT_PACKET_SIZE = 1
socket.DCCP_SOCKOPT_SERVICE = 2
socket.SOCK_DCCP = 6
socket.IPPROTO_DCCP = 33
socket.SOL_DCCP = 269
packet_size = 256
address = (socket.gethostname(),12345)
# Create sockets
server,client = [socket.socket(socket.AF_INET, socket.SOCK_DCCP,
socket.IPPROTO_DCCP) for i in range(2)]
for s in (server,client):
s.setsockopt(socket.SOL_DCCP, socket.DCCP_SOCKOPT_PACKET_SIZE, packet_size)
s.setsockopt(socket.SOL_DCCP, socket.DCCP_SOCKOPT_SERVICE, True)
# Connect sockets
server.bind(address)
server.listen(1)
client.connect(address)
s,a = server.accept()
# Echo
while True:
client.send(raw_input("IN: "))
print "OUT:", s.recv(1024)
有关DCCP的更多信息: https://www.sjero.net/research/dccp/ https://wiki.linuxfoundation.org/networking/dccp
TL; DR:dccp是一种提供拥塞控制(如tcp)的协议,不保证数据的可靠性或有序传递(如udp)。标准的linux内核实现了dccp。