problem with tcp socket in my mmorpg project

Hi Buddies, I’ve been working on a mmorpg project for months. And I am caught in a serious problem that seems like can’t be solved by myself. Plz help me locate where and what the problem is.

When the TCP Lib (C# base) is connecting to TCP server (C++ base), random terrible lag occurs to positions Sync of characters, so are the others like attacks, spells. However the lag never happens when we use Mac clients, it only occurs when it’s connected from iPad clients. And yet, which is more on iPad, big big lag like 2-3secs happens frequently!
By tests I found that packages actually only deliver 1-2 secs after the program has already invoked API to send it. The frequency is around 2 times in 10. Same frequency with packs delivering, the same problem occurs when packs receiving.

One thing for sure is it will never happen when the characters are connected from PC clients. I confirmed the network condition is fine(ping less that 1ms),and the server lag is not to blame too (no more than 20ms). CPU utilization of IOS system is under 60% when the program runs.

Can someone point out the right way for me to sort it?

you likely flood the pipe and the GC

Use the instruments and the unity iOS Pro profiler connection to the device to identify the exact root.

the fact that it runs fast on mac but not ipad implies that something is definitely overloading the cpu as thats the only major difference beside ram (in that case it would be the GC)

under 60% only says something if it is the ipad1. ipad2 has 2 cores yet unity only makes use of 1 (beside animation when you are on unity 3.4+)

Thx for the post
Through tests we have located where the problem is.
Nagle algorithm, which repacks pieces of small packs and send later until they get big enough for efficiency consideration, is disabled as default during the case of TCP SOCKET connections between MAC or PC and my server. But when it comes to IOS, Nagle algorithm is set to be able as default. That is exactly the reason causing lag.

Well, since that now my problem becomes: how to disable Nagle algorithm on IOS?

On PC, I know and I can disable it by API setsocketopt(sock_handle,IPPROT_TCP,TCP_NODELAY,bool);
But on ios when I try cfsocket and have the option set to be disable, it just doesn’t work out.

This not matching the thread title now, maybe it’s better to post a new one……