Unit 3: Basic Client-Server Communications - Sockets
1. First steps with Java sockets
In this part, we are going to learn how to communicate between two parts of an application using Java sockets. These parts can run on the same machine or (more commonly) on different machines connected via a network or the Internet.
Estimated time: 2,5 hours
- In this document, you will find all the content for this session:
- First, you will be introduced to Java sockets and the two main types: TCP and UDP.
- Next, you will learn how to implement basic client and server sockets using both the TCP and UDP protocols, with simple examples for each. Exercises 1 and 2 will allow you to practice these basic connections.
- Finally, you will explore how to use threads in socket applications to handle multiple client connections simultaneously. Exercise 3 guides you through adding threading to your client-server socket applications.
2. Some advanced concepts about sockets
In this part, you will learn advanced strategies for working with Java sockets.
Estimated time: 4 hours
- In this document, you will find all the content for this session:
- First, you will learn how to serialize complex objects in socket applications. To do this, you will need to create a third project — separate from the client and server projects — to store the data that will be shared between them. This shared project must then be linked to both the client and server projects. Object serialization can be performed using either TCP or UDP sockets. Exercises 1 and 2 will allow you to practice serialization with each protocol.
- Next, you will explore multicast sockets and their main purpose: sending messages simultaneously to all clients connected to a multicast group. To practice with multicast sockets, complete Exercises 3 and 4.