Best way to use Sockets in C#
Posted on 2012-03-19
I have seen a lot of ways to deal with sockets in VB.NET, however I am not sure which way is the best way that allow:
1. Sending string data (both sides)
2. Sending binary data (both sides, including large binary data and files)
Important: I DONT want to know how to use Sockets, I already know that.
I want the best way to use to achieve what I said above.
Basically I want the following methods to be included:
I want to be using TcpListener/TcpClient.
The problem I usually face is when I have 1025 bytes buffer and I receive for example two binary buffers, one use the full 1025 and the other use for example 400 bytes from 1024, so if i wrote that to a file it will write about 2050 which is invalid file size, the file size is only 1425 bytes.