Sockets Lectures
This module shows how to communicate using TCP and UDP sockets.
1. Streams
This part covers stream handling using the Java IO API.
Source Code
The programming examples can be found in GitHub, https://github.com/KTH-ID1212/streams Links to an external site.
Videos
- Introduction to stream handling
Links to an external site.
-
Stream usage in the file handling program
Links to an external site.
The video above illustrates the following.
- Layered architecture
- Design and coding best practices
- How to use the ForkJoinPool thread pool, which is built-in in the JDK
- A multithreaded command line user interface
- Java IO streams
- File handling with Java IO and Java NIO
2. Sockets
This part covers TCP and UDP sockets using the package java.net.
Source Code
The programming examples can be found in GitHub, https://github.com/KTH-ID1212/sockets Links to an external site.
Videos
-
Introduction to socket communication
Links to an external site.
This is the presentation used in the video, sockets.pdf Download sockets.pdf.
-
A small UDP example, UDP streaming program
Links to an external site.
The example above illustrates the following.
- How to use UDP sockets
- Server-side thread handling
- Coding best practices
-
A small TCP example, an HTTP client and an HTTP server
Links to an external site.
The examples above illustrate the following.
- How to use TCP sockets for the HTTP protocol
- The need of a length header
- The need to call flush() when sending data through a stream
- Server-side thread handling
- Coding best practices
- A bigger example, chat program
- Architecture and communication protocol in the chat program
Links to an external site.
- Running the chat program
Links to an external site.
- Chat client code
Links to an external site.
- Chat server code
Links to an external site.
- Using serialized objects instead of a text-based protocol
Links to an external site.
- Architecture and communication protocol in the chat program
Links to an external site.
- The chat program example above illustrates the following.
- A layered architecture
- Design and coding best practices
- The observer design pattern
- Client-side thread handling and server-side thread handling
- TCP communication with blocking sockets
- A custom communication protocol, both a text-based protocol and a protocol using serialized objects are demonstrated
- How to use the ForkJoinPool thread pool, which is built-in in the JDK
- How to use the debugger