I implemented a Client and Server model that uses Socket with thread
When I want to pass only a string from Client to the Server, it works. But I want to pass an object
To answer your second question: for maximum maintainability, the class Command
should be in a separate assembly that both Client and Server reference.
To answer your first question: you are attempting to deserialize from an empty stream on your server, just as the exception tells you. You need to copy the bytes you read from the clientStream
into the memoryStream
before you deserialize from the memoryStream
. Alternatively, use the clientStream
directly rather than using the memoryStream
; this may require reconsidering your protocol.
Finally, I wholeheartedly agree with @Andrey: consider using WCF. It's way way way better than raw sockets.