Book contents
- Frontmatter
- Contents
- Preface
- Acknowledgements
- Part I Introduction to Java
- Part II Java and the network
- 13 Java networking basics
- 14 A Java web server
- 15 Client/server with sockets
- 16 Distributed computing
- 17 Distributed computing – the client
- 18 Java Remote Method Invocation (RMI)
- 19 CORBA
- 20 Distributed computing – putting it all together
- 21 Introduction to web services and XML
- Part III Out of the sandbox
- Appendix 1 Language elements
- Appendix 2 Operators
- Appendix 3 Java floating-point
- Index
- References
15 - Client/server with sockets
Published online by Cambridge University Press: 08 January 2010
- Frontmatter
- Contents
- Preface
- Acknowledgements
- Part I Introduction to Java
- Part II Java and the network
- 13 Java networking basics
- 14 A Java web server
- 15 Client/server with sockets
- 16 Distributed computing
- 17 Distributed computing – the client
- 18 Java Remote Method Invocation (RMI)
- 19 CORBA
- 20 Distributed computing – putting it all together
- 21 Introduction to web services and XML
- Part III Out of the sandbox
- Appendix 1 Language elements
- Appendix 2 Operators
- Appendix 3 Java floating-point
- Index
- References
Summary
Introduction
In Chapter 14 we showed how to build a basic web server that sends files to browsers or to browser-like clients. In this chapter we present a more interesting socket-based client/server demonstration system that goes beyond just transmission of web pages. This new server sends data to a client, which then displays the data in histograms. This type of client/server system could be quite useful in various applications such as transmitting data from a remote experiment, running diagnostics under the direction of a client, installing calibration settings, and controlling an instrument remotely. For demonstration purposes, our server generates simulated data.
As in Chapter 14 we use sockets for our client/server communications [1–3]. Later chapters present RMI and CORBA based approaches. In a step-by-step manner we describe the concepts and the code techniques used in the client and server demonstration programs.
The client/server design
For the web server discussed in Chapter 14 we used socket communications. The server monitors a port with a ServerSocket, which returns a socket for a client whenever one requests a connection. The socket is passed to a thread that receives a request from the client for a file and then transmits that file if it is available. The server then breaks the connection and the session ends.
We can, however, create a client/server system in which the server maintains a connection for as long as the client desires.
- Type
- Chapter
- Information
- Publisher: Cambridge University PressPrint publication year: 2005