The socket client simply transmits data

Source: Internet
Author: User
Tags unpack

1. Integer conversion to binary _host for TCP transport = "127.0.0.1"        _port = 5678        _address = (_host, _port)        S=socket.socket (socket.af_ Inet,socket. SOCK_STREAM)        Connect_result = S.connect (self._address) #二进制的字符串        s.send (b ' Welcome to server! ') #! Represents the large-endian s.send (Struct.pack (">i", 12345)) #与erlang的不定长数据包, which first accepts the header. Bytes_msg_length = S.RECV (2)        #解压数据, the return value is a tuple, and the valid value is the first position within a tuple.        msg_length= struct.unpack (">h", bytes_msg_length)        bytes_msg= s.recv (msg_length[0])                msg= Struct.unpack (">f", bytes_msg) print (msg[0])

The socket client simply transmits data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.