Network framework only receiving first chunk of data

Hey

I've run into an issue using network framework in that I'm only receiving the first chunk of data. I really can't tell if it's how I'm using the Network.framework bits on the client side, or if it's an issue with the server side (I'm using Vapor).

I put together a basic example project that hopefully demonstates the issue. If you run the server target and then the client target for me I receive 174 bytes in the first receive, receive is then called again but nothing happens after that I'm at a bit of a loss as to why

https://github.com/GP89/TestStaticServer

Thanks!

Ok I realised what my problem was. It was casting the data to (char*). I did this as that's the type I needed the data in. But strlen and other things will stop at the first null byte so it seemed like I was only receiving a little bit of the data. It will also read passed the end of the context when casting the data bytes to char*, then you get that data again on the next receive which is also an issue.

I'm still confused however why is_complete isn't coming back as true, so it sits on the next receive forever

I'm still confused however why is_complete isn't coming back as true, so it sits on the next receive forever

If you’re using a stream-oriented protocol such as TCP, there are no protocol-level message boundaries [1]. If the sender sends you 2 chunks of 2048 bytes, you might receive:

  • 2 chunks of 2048 bytes

  • 1 chunk of 4096 bytes

  • 4096 chunks of 1 byte

  • 2 chunks of 1450 bytes followed by 1 chunk of 1196 bytes

  • Or any other combination

There’s no way that is_complete can be set at message boundaries because message boundaries aren’t reflected in the underlying protocol. With TCP, you’ll only see is_complete set at the end of the stream.

If you need message boundaries on top of TCP, add a framing protocol. The easiest to apply here is WebSocket, which has built-in support in Network framework.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Technically TLS-over-TCP adds message boundaries but that’s not reflected in most TLS APIs, including Network framework, where the goal is for TLS-over-TCP to act as much like TCP as possible.

Network framework only receiving first chunk of data
 
 
Q