Click here to Skip to main content
15,909,566 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

If I have a client and a server program and want to call different tasks from the server how would I do this? For example if I want to send data to the server and make the server store this data in a database or if I want to receive data to the client from the database on the server?

Should I write a packet with a header telling the server what to do with the data? or is there other ways of doing this?
Posted
Comments
Mahesh Bailwal 10-Nov-13 9:28am    
According to my experience I think you should write a packet with a header telling the server what to do with the data.
maxbre 10-Nov-13 9:46am    
Alright, thanks

There are many ways to achieve that, but having some header is a good idea. Generally, all communications are better in prefixed form. Say, you have a message with variable size. Naturally, it's the best to tell the size first, the the reader would read just enough bytes. Same thing is with the messages of variable content. You may have some field which the reader receives first, and then, based on this information as on descriptor, the reader knows the expected structure of the rest of this message, and it can be done hierarchically.

Your question is way to vague to discuss it in further detail, but I hope you get the idea.

However, all such considerations might be too low-level for the application. The thing is: the whole complex of such problem is already solved for you. If you really want to use raw sockets, not WCF, not .NET remoting, you can use your socket streams with pre-serialized data. In other forms, using of serialization will have you to exchange your programming objects instead of raw data, which will be automatically deserialized on the reading end.

Please see:
http://en.wikipedia.org/wiki/Serialization[^],
http://msdn.microsoft.com/en-us/library/7ay27kt9%28v=vs.110%29.aspx[^].

In many cases, I would recommend to use the best serialization (at least in some aspects) offered in .NET FCL — Data Contract:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

Please see my past answers:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

—SA
 
Share this answer
 
I think the best and simplest idea for this using a web service. I think there is nothing involved in working with any type of sockets. If you can able to write a web services your life becomes easier. Google it on how to write a webservice in dotnet, you can choose between ASMX or WCF web services.

Any help, post it here

Thanks
Ganesh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900