Exemplo n.º 1
0
    public async void Send(TopicData topicdata)
    {
        Debug.Log("topicdata: " + topicdata);

        MemoryStream      memory_stream       = new MemoryStream();
        CodedOutputStream coded_output_stream = new CodedOutputStream(memory_stream);

        topicdata.WriteTo(coded_output_stream);
        coded_output_stream.Flush();
        Debug.Log("coded_output_stream: " + coded_output_stream);
        var bytebuffer = memory_stream.ToArray();

        Debug.Log("buffer length: " + bytebuffer.Length);

        var array_segment = new ArraySegment <Byte>(bytebuffer);

        Debug.Log("array_segment length: " + array_segment.Count);
        CancellationToken cancellation_token = new CancellationToken();
        await client_websocket.SendAsync(array_segment, WebSocketMessageType.Binary, true, cancellation_token);

        /*try
         * {
         *  await client_websocket.SendAsync(array_segment, WebSocketMessageType.Binary, true, cancellation_token);
         * }
         * catch (Exception ex)
         * {
         *  Debug.LogError(ex.ToString());
         * }*/
    }
Exemplo n.º 2
0
    public async Task <CancellationToken> SendTopicDataImmediately(TopicData topicData)
    {
        MemoryStream      memoryStream      = new MemoryStream();
        CodedOutputStream codedOutputStream = new CodedOutputStream(memoryStream);

        topicData.WriteTo(codedOutputStream);
        codedOutputStream.Flush();
        var bytebuffer = memoryStream.ToArray();

        return(await this.SendBytes(bytebuffer));
    }