Hi, I can't get to deserialize objects while sending them over a socket while using BinaryFormatter
that's the code for a server which receives data from client:
16 Replies
and this is the code for a client which sends data
also a data class:
I get:
Just note, BinaryFormatter is insecure and cannot be made secure.
Prefer other APIs and/or libraries, such as MessagePack
one question
why sockets are so godamn ducked up
whyyyyyyyy …
Huh?
idk
I just spent like a good 3h trying to make this "thing" work
Because networking is complicated
I know, I did this kind of stuff in java
hard to understand as a beginner.
Practice makes perfect.
but back then … it just clicked
Sockets is pretty much the same for all languages
Well, basics at least.
although now… its like wtf is going on
ye
Whenever you send a packet, include the length of the packet with it
as well as the type of the packet
Packet Type | Packet Length | Payload
1. Allocate the bytes required for header.
2. Receive bytes equal to header size (which contains the header IE; Type and Length)
3. After that receive bytes equal to the size of packet length.
4. Check packet type, deserialize based on the type of packet.alrighty, thanks
Just note, also validate everything received.
Such as if you receive an invalid packet, it will not try and deserialize it.
Usually you just kick the user if they send an invalid packet
oke doke
thanks man
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.