2

I'm coding a concurrent ATM application having a Client and a Server.

I need to know how Socket programming can be used in this to call Server methods (request for his current balance, transfer funds etc) and get Objects returned to Client.

I do not want just to pass text using System.out.println like mentioned in Lesson: All About Sockets

4 Answers 4

4

You should use Javas RMI Lib for this.

You can find a small example here: http://download.oracle.com/javase/1.3/docs/guide/rmi/getstart.doc.html

Sign up to request clarification or add additional context in comments.

2 Comments

isn't it possible with Sockets? I want a simple working solution.
it is possible with sockets but RMI is a lot easier in this case.
4

You need to serialize your data, send it, and deserialize it. See Lesson: Basic I/O for an introduction to the Java serialization classes.

Comments

3

Sockets are just a way to open a communication channel between a server and a client. A socket connection just enables you to send bytes from one machine to the other, nothing more. In particular, sockets do not directly provide a way to call methods on another machine.

You will need to implement an application-level protocol on top of sockets, or use some existing (standard) application-level protocol. You could use RMI as suggested by ashiaka, or for example JAX-RS (Java's standard API for RESTful web services). Both these will use sockets to get the data across from one machine to the other.

So yes, it is possible using sockets, but you need to use something on top of that to actually remotely call methods.

Comments

1

I found this tutorial really helpful http://java.sun.com/developer/technicalArticles/ALT/sockets/

They say:

RMI = Sockets + Object Serialization + Some Utilities

Thanks guys for contributing!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.