zeromq / netmq

A 100% native C# implementation of ZeroMQ for .NET
Other
2.97k stars 745 forks source link

Sometime receiving half data #1105

Open aftabi2v opened 2 months ago

aftabi2v commented 2 months ago

Environment

NetMQ Version:    4.0.1.13
Operating System:  Windows 10 x64
.NET Version:     4.7.2

Explanation

My netmq client is receiving half data from the server. This happens around 0.1 % times. Since I am receiving data of a model I am unable to deserialize the data.

Code

public ZeroMqVAClient(string ip, string port, string topic)
{
    try
    {
        subscriber = new SubscriberSocket();
        subscriber.Options.ReceiveHighWatermark = 1000;
        address = "tcp://" + ip + ":" + port;
        subscriber.Connect(address);
        subscriber.Subscribe("");
        poller = new NetMQPoller { subscriber };
        subscriber.ReceiveReady += subscriber_ReceiveReady;
        poller.RunAsync();
    }
    catch (Exception ex)
    {

        ExceptionHandler.handleException(ex.Message);
    }
}

private void subscriber_ReceiveReady(object sender, NetMQSocketEventArgs e)
{
    string messageReceived = string.Empty;
    try
    {

        if (subscriber.TryReceiveFrameString(out messageReceived))
        {
            var evnt = JsonConvert.DeserializeObject<List<VAAlertArgs>>(messageReceived);
            foreach (var item in evnt)
            {
                OnAlertRecievedEvent(item);
            }

        }
    }
    catch (Exception ex)
    {
        ExceptionHandler.handleException(ex);
    }
}

The average message received size is 149594 character but sometimes I only get 8183 character of data.