danielmhanover
danielmhanover

Reputation: 3124

iOS Successive TCP Requests Fail

I am currently developing an iOS app which uses CFStream to communicate with a C# server. Sending 1 TCP packet over this connection does what its supposed to. However, if I try to send two packets, they both fail.

The server is designed to be asynchronous like the one here. The iOS side is designed using the CFStream classes, as dictated in this tutorial.

Why does this occur and how can I fix it? All help is greatly appreciated!

EDIT: I have just tried replacing the C# server with a Python server, and the system worked flawlessly, which would hint that the problem is server-side. Maybe the server is accidentally closing the connection after receiving the first packet?

Upvotes: 2

Views: 267

Answers (2)

danielmhanover
danielmhanover

Reputation: 3124

It turns out the server was set up to close the connection after it sent its first packet of information to the client. The solution was to add a

handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0,
        new AsyncCallback(ReadCallback), state);

in the ReadCallback() method, to ensure it would resume listening to the client after processing its request.

Upvotes: 0

Christian Garbin
Christian Garbin

Reputation: 2532

Start by figuring out for sure who is closing the TCP socket. Run Wireshark on the server to check who is sending a FIN or RST in that connection. That will split the problem in half.

Upvotes: 1

Related Questions