Processing client messages

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2008
Posts: 52
Reputation: Bhoot is an unknown quantity at this point 
Solved Threads: 1
Bhoot's Avatar
Bhoot Bhoot is offline Offline
Junior Poster in Training

Processing client messages

 
0
  #1
May 10th, 2009
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.
Bhoot
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Processing client messages

 
0
  #2
May 10th, 2009
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.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 52
Reputation: Bhoot is an unknown quantity at this point 
Solved Threads: 1
Bhoot's Avatar
Bhoot Bhoot is offline Offline
Junior Poster in Training

Re: Processing client messages

 
0
  #3
May 10th, 2009
Originally Posted by Ramy Mahrous View Post
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.
Bhoot
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,219
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 573
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast

Re: Processing client messages

 
0
  #4
May 11th, 2009
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.

  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
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,219
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 573
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast

Re: Processing client messages

 
0
  #5
May 11th, 2009
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:

  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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 52
Reputation: Bhoot is an unknown quantity at this point 
Solved Threads: 1
Bhoot's Avatar
Bhoot Bhoot is offline Offline
Junior Poster in Training

Re: Processing client messages

 
0
  #6
May 11th, 2009
Originally Posted by sknake View Post
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:

  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.
Bhoot
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,219
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 573
Sponsor
sknake's Avatar
sknake sknake is online now Online
.NET Enthusiast

Re: Processing client messages

 
0
  #7
May 11th, 2009
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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 52
Reputation: Bhoot is an unknown quantity at this point 
Solved Threads: 1
Bhoot's Avatar
Bhoot Bhoot is offline Offline
Junior Poster in Training

Re: Processing client messages

 
0
  #8
May 11th, 2009
Originally Posted by sknake View Post
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.
Bhoot
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC