Skip to content

Instantly share code, notes, and snippets.

@chaosx
Last active April 2, 2017 09:50
Show Gist options
  • Select an option

  • Save chaosx/a6fd29472ae0874461705e6684bb6e35 to your computer and use it in GitHub Desktop.

Select an option

Save chaosx/a6fd29472ae0874461705e6684bb6e35 to your computer and use it in GitHub Desktop.
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)
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