MCPcopy
hub / github.com/TarsCloud/TarsGo / Send

Function Send

tars/protocol/push/server.go:30–47  ·  view source on GitHub ↗

Send push message to client

(ctx context.Context, data []byte)

Source from the content-addressed store, hash-verified

28
29// Send push message to client
30func Send(ctx context.Context, data []byte) error {
31 conn, udpAddr, ok := current.GetRawConn(ctx)
32 if !ok {
33 return fmt.Errorf("connection not found")
34 }
35 rsp := &requestf.ResponsePacket{
36 SBuffer: tools.ByteToInt8(data),
37 }
38 rspData := response2Bytes(rsp)
39 var err error
40 if udpAddr != nil {
41 udpConn, _ := conn.(*net.UDPConn)
42 _, err = udpConn.WriteToUDP(rspData, udpAddr)
43 } else {
44 _, err = conn.Write(rspData)
45 }
46 return err
47}
48
49// NewServer return a server for pushing message
50func NewServer(s PushServer) transport.ServerProtocol {

Callers 1

OnConnectMethod · 0.92

Calls 5

GetRawConnFunction · 0.92
ByteToInt8Function · 0.92
response2BytesFunction · 0.85
WriteMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected