Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "crypto/tls"
- import "bufio"
- import "encoding/binary"
- import "fmt"
- import "bytes"
- import "time"
- type packet struct {
- a uint32
- b []byte
- }
- func pack(d string) []byte {
- buf := bytes.Buffer{}
- u := len([]byte(d))
- p := packet{
- a: uint32(u),
- b: []byte(d),
- }
- err := binary.Write(&buf, binary.BigEndian, p.a)
- if err != nil {
- fmt.Println(err)
- }
- buf.Write(p.b)
- return buf.Bytes()
- }
- func initIt() {
- }
- func main() {
- initIt()
- fmt.Println("-------> Connect")
- connect:
- conf := &tls.Config{ // enable TLS client encryption
- InsecureSkipVerify: true,
- }
- tlsConn, err := tls.Dial("tcp","127.0.0.1:5050", conf);
- if err != nil {
- fmt.Println(err)
- time.Sleep(5000 * time.Millisecond) // wait 5 secs
- goto connect
- }
- defer tlsConn.Close()
- reader := bufio.NewReader(tlsConn)
- //writer := bufio.NewWriter(tlsConn) // not neccessary, just use c.Write(...)
- // client login
- fmt.Println("-------> Client login")
- tlsConn.Write(pack("login test:test"))
- // //!REMOVEME d1.Reset(
- time.Sleep(1000 * time.Millisecond)
- var p uint32 // packet size
- binary.Read(reader, binary.BigEndian, &p)
- fmt.Println(int(p))
- buf1 := make([]byte, int(p))
- fmt.Println("-------> Client login [read response...]")
- reader.Read(buf1)
- fmt.Println(string(buf1))
- fmt.Println(len(string(buf1)))
- fmt.Println("-------> Client ping")
- tlsConn.Write(pack("ping 0000-00-00 00:00:00"))
- fmt.Println("-------> Client ping [read into p2...]")
- var p2 uint32 // packet size
- binary.Read(reader, binary.BigEndian, &p2)
- fmt.Println(p2)
- buf1 = make([]byte, int(p2))
- fmt.Println("-------> Client ping [read response...]")
- reader.Read(buf1)
- fmt.Println(string(buf1))
- time.Sleep(50000 * time.Millisecond)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement