1

All the examples i found are sending only text/string data over the network. I figure out how to send different types of objects (ArrayLists etc). I'm now trying to find out how to process commands sent from the client on the server. From the client i have to : add ä "Student" in the database delete a student in the database get all students in the database etc.

so, if i create a protocol on the client side with a method "processCommand" sometimes i have a different number of parameters, depending on the request from the client ( when adding a student, i have to send the student object) , ( when getting data from the database i don't have to send any parameters) ; also i have to return different type of objects. How can i do this ? Thank you very much.

2
  • Check out WCF : msdn.microsoft.com/WCF - it supports client-server communication, uses TCP/IP protocol (amongst others) .... Commented Apr 20, 2011 at 7:58
  • you can try serialization if you want to send objects Commented Apr 20, 2011 at 8:01

1 Answer 1

3

As suggested by @marc_s. There is no reason to reinvent the wheel. Use WCF with tcpBinding.

If you need to do it by yourself you need to use some kind of serialization. You also need to attach a header since TCP is stream based and do not guarantee that everything arrives in the same Receive.

I would do it like this:

  1. Serialize your object into a byte buffer using BinaryFormatter.
  2. Send a header containing version (an int) and number of bytes in the byte buffer (int)
  3. Send the byte buffer.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.