Khalid
Khalid

Reputation: 75

Java client server application

I want to write a simple client server application where they are deployed in different locations, the server needs to expose two public methods to the client and keep data exchange between them to a minimum, I was going down the path of using sockets, however, how does the client call a public method on the server? Or is there another way?

Upvotes: 0

Views: 113

Answers (2)

Peter Lawrey
Peter Lawrey

Reputation: 533500

You need to encode the action and response you want in a some text or binary format.

A simple way to do this is to send the name of the method you want to call and the other end reads the name and calls the method of that name. If you want to make it shorter you can send (byte) 1 to call the first method and (byte) 2 to call the second method etc. and use a switch statement to call the appropriate method.

Upvotes: 1

Jeff Storey
Jeff Storey

Reputation: 57192

There are several ways to do this, but I would take a look at RMI. It makes calling methods on remote java objects pretty easy. There are still going to be low level protocols involved (sockets/tcp), but you won't need to manage that explicitly yourself.

Upvotes: 2

Related Questions