943,650 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 513
  • C# RSS
May 10th, 2009
0

Processing client messages

Expand Post »
In my client-server architecture, the cilent-side application would send specific messages to the server-side application.
How should i handle those messages?
Previously, in a small project, i had just passed the received message to a method where it would process the message through a switch case structure.
However, this doesnt seem feasible as this is a much bigger project.
Can anyone provide me a better alternative.
I have thought of using delegate. However, i would rather wait for some suggestions.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Bhoot is offline Offline
53 posts
since Oct 2008
May 10th, 2009
0

Re: Processing client messages

Which technology you use? WCF or just socket programming what's the importance of data? all of these questions determine the best practice of implementing passing messages.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
May 10th, 2009
0

Re: Processing client messages

Which technology you use? WCF or just socket programming what's the importance of data? all of these questions determine the best practice of implementing passing messages.
i am developing it in C#.NET, using the helper classes - TcpClient, TcpListener. (i mean no direct use of Socket).
Also i am using asynchronous method of communication.
The project i am developing is a client monitoring application. Hence, the data is much more important. They are the messages, rather commands that are sent by the server-side application to the client-side application.
For example, if i would like to start keylogging on some client PC, i would hit a button on my server application, sending a command to start keylogger module on that client.
Also, then the client would send the whole log through a stream to the server.
Thus, its a two-way communication.
I think this would suffice. If you wish any more information though, you may ask.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Bhoot is offline Offline
53 posts
since Oct 2008
May 11th, 2009
0

Re: Processing client messages

You should link in your other thread for future questions on this project to give people a good background on what you're doing without having to retype it all

Take a look at what HTTP, FTP, or many other protocols do. They assign numeric values for a command and then have metadata beyond that.

Just switch() the int off to the desired logic. This also allows you to implement new commands on one side and not the other, for unknown ints you can return a "command not understood" so you know that its' software needs to be updated.

C# Syntax (Toggle Plain Text)
  1. <- Microsoft FTP Service
  2. -> USER *
  3. <- 331 Password required for upload.
  4. -> PASS *
  5. <- 230 User * logged in.
  6. -> QUIT
  7. <- 221

HTTP:
404 - not found
403 - forbidden
301 - resource moved perm.
302 - resource moved temp.

I've sure you have seen those before
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
May 11th, 2009
0

Re: Processing client messages

Oh.. one more point I wanted to mention. Enum's are great for this so you don't have to memorize the command codes. I use numerics exactly as I described above for IPC between windows services and their desktop configuration apps.

You can cast an enum to/from an int, but watch out when you are doing int->enum as it will return a number even if the enum doesn't explicitly exist for it. I don't have visual studio handy but you can set enums:

C# Syntax (Toggle Plain Text)
  1. public enum Commands
  2. {
  3. StartKeyLogger = 1,
  4. StopKeyLogger = 2,
  5. }

Then use Enum.IsDefined(typeof(Commands), someInt); before you convert the int to enum.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
May 11th, 2009
0

Re: Processing client messages

Click to Expand / Collapse  Quote originally posted by sknake ...
Oh.. one more point I wanted to mention. Enum's are great for this so you don't have to memorize the command codes. I use numerics exactly as I described above for IPC between windows services and their desktop configuration apps.

You can cast an enum to/from an int, but watch out when you are doing int->enum as it will return a number even if the enum doesn't explicitly exist for it. I don't have visual studio handy but you can set enums:

C# Syntax (Toggle Plain Text)
  1. public enum Commands
  2. {
  3. StartKeyLogger = 1,
  4. StopKeyLogger = 2,
  5. }

Then use Enum.IsDefined(typeof(Commands), someInt); before you convert the int to enum.
ohk..yup..i know the enum type.
I thought to follow the same method. Indeed, i would follow what you suggested.
i will just use the switch case to direct the command to some function that handles that command. You may correct me though if i am wrong.
And yaa..i will link up all my posts as you said.
But what did you mean by that? should i just put up my links to other posts in any of my upcoming posts ?
Or is there any special facility here? i couldng find any.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Bhoot is offline Offline
53 posts
since Oct 2008
May 11th, 2009
0

Re: Processing client messages

What I meant was in the original post you went in to great detail about what the application does and provided examples of the commands you planned on implementing.

The original post in this thread was not enough information and had I not been involved with your original post I would have asked the same question Ramy did. *What* you are doing guides *how* you will do it, so you should give the same background on what you are doing for questions like this.

Its' all for your benefit so you can get your posts answered quicker and with better insight

Good luck and please mark this thread as solved if your question has been answered.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
May 11th, 2009
0

Re: Processing client messages

Click to Expand / Collapse  Quote originally posted by sknake ...
What I meant was in the original post you went in to great detail about what the application does and provided examples of the commands you planned on implementing.

The original post in this thread was not enough information and had I not been involved with your original post I would have asked the same question Ramy did. *What* you are doing guides *how* you will do it, so you should give the same background on what you are doing for questions like this.

Its' all for your benefit so you can get your posts answered quicker and with better insight

Good luck and please mark this thread as solved if your question has been answered.
yup..i got it...i will link in the posts from now.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Bhoot is offline Offline
53 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Cannot access a project's namespace in a solution
Next Thread in C# Forum Timeline: Data binding to a Radio Button





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC