通过套接字发送sockaddr_in结构

时间:2017-11-19 20:07:43

标签: c sockets

如何通过套接字发送sprintf(message, "%hu %hu %lu %c", server.sin_family, server.sin_port, server.sin_addr, server.sin_zero); send(sock , message , 16, 0); ? 我正在尝试这种方式,但它无法正常工作

客户端

recv(client_sock , convert , 16 , 0); 
sscanf(convert, "%hu %hu %lu %s", &my_addr.sin_family, &my_addr.sin_port, &my_addr.sin_addr, &my_addr.sin_zero);
printf("%hu %s %lu %s", my_addr.sin_family, my_addr.sin_port, my_addr.sin_addr, my_addr.sin_zero);

服务器

sin_family = AF_INET
sin_port =   8888
sin_addr =  "127.0.0.1"
sin_zero = (NOT SETTED)

只是想将my_addr结构发送到服务器,为什么客户端没有正确接收它?

即。发送

sin_family = 2                 //enum AF_INET == 2
sin_port =   45346
sin_addr =  "127.0.0.1"
sin_zero = X

我有stdout

sin_family

sin_addrsin_port都可以。 from twisted.web.server import Site from twisted.web.static import File from twisted.web.resource import Resource from twisted.internet import reactor class MainPageDispatcher(Resource): isLeaf = True def __init__(self): super().__init__() def render_GET(self, request): request.setHeader(b"content-type", b"text/html") return "hello" return bytes("hello", "utf-8") root = MainPageDispatcher() factory = Site(root) reactor.listenTCP(8888, factory) reactor.run() 不正确。怎么了? (我不太关心sin_zero)。

感谢您的合作!

0 个答案:

没有答案