Last active
April 2, 2017 09:50
-
-
Save chaosx/a6fd29472ae0874461705e6684bb6e35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "encoding/binary" | |
| "bytes" | |
| ) | |
| bs := make([]byte, 4) | |
| msg := "ssssssss" | |
| binary.BigEndian.PutUint32(bs, uint32(len(msg))) | |
| msgFull := [][]byte{bs, msg} | |
| msgByte := bytes.Join(msgFull, []byte("")) | |
| fmt.Printf("%s", msgByte) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def send_msg(self, sock, msg): | |
| # Prefix each message with a 4-byte length (network byte order) | |
| msg = struct.pack('>I', len(msg)) + msg | |
| sock.sendall(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment