Reputation: 1247
How to invoke a method on the server from client? I'm using java socket. I am able to send and receive messages, but do not know how to invoke methods. Should I use switch(case)? If text equal name of the method, run this method. What is the correct/best way?
Upvotes: 0
Views: 1745
Reputation: 39477
Send some messages to the server. The server should then decide based on the message received which method to invoke. E.g. if it gets "message1"
, it could call method1
, if it gets "message2"
, it could call method2
. Yes, you can use a switch statement for this. The messages do not need to be strings, they could be numbers.
Upvotes: 1
Reputation: 178
Use an Opcode that correspond to your methods and then Switch on it.
Easier to maintain then handling the method names directly
Upvotes: 1