Question

I'm trying to connect to an UAP Server (used for sending and receiving USSD messages in Huawei) using Socket class but there's a problem while receiving data from server. I can connect to server correctly and also I can send data to server but I have problem with receiving data.

This is my code for connecting and sending message:

IPAddress ipAddress = IPAddress.Parse("127.0.0.1"); //server
IPEndPoint remoteEP = new IPEndPoint(ipAddress, 2020);

clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

clientSocket.Connect(remoteEP);

//bind to socket, here I send bind message
Bind();

and inside the Bind function, I call receive method to get data from server:

private static void receive()
{
    try
    {
        // Create the state object.
        StateObject state = new StateObject();
        state.workSocket = clientSocket;

        // Begin receiving the data from the remote device.
        clientSocket.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
            new AsyncCallback(receiveCallback), state);

    }
    catch (Exception ex)
    {
        Console.WriteLine("receive | " + ex.ToString());
    }

}//receive

Here you can see my Wireshark log while connecting, sending data and receiving data from server:

Wireshark log

But as you can see, last two messages from server are highlighted with red color which means there's a problem with receiving data from server. Also I don't see data field in details:

detail of a message

I really don't know what's the problem, is this a problem with server or not? Should I use another Socket client to connect and receive data from server or not?

Was it helpful?

Solution

TCP reset packets aren't a part of your application level protocol and your application shouldn't be expected to see them.

Exactly what is the incorrect behavior with your application, because with what you've posted, I'm not seeing any problems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top