Hi! I am a professional programmer but I am very new to network programming.
As an hobby, I am studying asio and socket programming.
I have create rudimentary client/server programs (one connects the other accepts).
Nothing fancy really.
I run both client and server on the same computer and I transfer an image of roughly 8mb (really its just an 8mb buffer but I interpret it as an image) from the client to the server then from the server and the client. A simple roundtrip test using asio_read/asio_write.
Now this is where things are getting weird at least to me.
If my client connects on the server using either "localhost" or the router given address of the server (192.168.1.16) everything is fine - all the time - meaning I can do the roundtrip test hundreds of time without a single byte difference.
Now, I have setup port forwarding in my router and tried the same test with my public IP address given by my ISP. Once the client is connected using this IP I can do the roundtrip test again but now I see *some* garbage data in the image. The transfer is not longer or shorter... just some "random" data overwrites in the middle of the buffer.
I have used a hexdiff program to see the actual bytes of garbage and while I can't understand all of it, I see snippets of strings of what looks like some broadcast messages.
stuff like :
- "googlerpc-3._googlerpc.tcp.local"
- "Netgearxr500"
appears in the "garbage" data.
With all that in mind, I got a few questions:
- Is it really possible for the router or some external actor to inject crap in a TCP connection without actually connecting to the socket? (I do not see more than one client connection on the server)
- So should I be coding fail-safes for corrupted data in TCP transfers?
(not for security reasons but just so my stuff works?)
- I understand that 8mb is big for a single asio_read command but at the same time I thought that it was safe to use like that. Could my problem be related to asio somehow? I know asio_read / asio_write are compound operation made up of "small" transfer operations? Maybe I need to configure something on asio initialization so it does not "sniff" the network?
(that was a colleague suggestion - "maybe the socket is sniffing the network?")
- Another colleague suggested that I split large transfers into smaller ones with some hash/checksum to verify integrity. All good but I thought that that was the point of TCP?
What I have tried:
- Verified all memory allocation and made sure the data is present until the async operations are completed.
- Updated the router + factory reset just in case.
- Disconnected all google home devices that I suspected could broadcast data.
- Made both client & server programs completely single threaded.