Skip to content

Commit

Permalink
Improve Socket API section
Browse files Browse the repository at this point in the history
  • Loading branch information
ludelafo committed Nov 6, 2023
1 parent 81844ef commit 30be65e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
48 changes: 28 additions & 20 deletions 13-java-tcp-programming/COURSE_MATERIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ This work is licensed under the [CC BY-SA 4.0][license] license.
- [Objectives](#objectives)
- [TCP](#tcp)
- [The Socket API](#the-socket-api)
- [Client/server common functions](#clientserver-common-functions)
- [Client structure and functions](#client-structure-and-functions)
- [Server structure and functions](#server-structure-and-functions)
- [Client/server common methods](#clientserver-common-methods)
- [Client workflow and methods](#client-workflow-and-methods)
- [Server structure and methods](#server-structure-and-methods)
- [Processing data from streams](#processing-data-from-streams)
- [Variable length data](#variable-length-data)
- [Handling one client at a time](#handling-one-client-at-a-time)
Expand Down Expand Up @@ -118,7 +118,7 @@ A socket can act as a client or as a server:
- A socket accepting connections is called a server socket.
- A socket initiating a connection is called a client socket.

### Client/server common functions
### Client/server common methods

| Operation | Description |
| ------------------- | ---------------------------------- |
Expand All @@ -127,28 +127,36 @@ A socket can act as a client or as a server:
| `getOutputStream()` | Gets the output stream of a socket |
| `close()` | Closes a socket |

### Client structure and functions
### Client workflow and methods

1. Create a socket (class `Socket`)
2. Connect the socket to an IP address and a port number
3. Read and write data from/to the socket
4. Flush and close the socket
In order to create a client, the following workflow is followed:

> 1. Create a socket (class `Socket`)
> 2. Connect the socket to an IP address and a port number
> 3. Read and write data from/to the socket
> 4. Flush and close the socket
The available methods are the following:

| Operation | Description |
| ----------- | ---------------------------------------------------- |
| `connect()` | Connects a socket to an IP address and a port number |

### Server structure and functions

1. Create a socket (class `ServerSocket`)
2. Bind the socket to an IP address and a port number
3. Listen for incoming connections
4. Loop
1. Accept an incoming connection - creates a new socket (class `Socket`) on a
random port number
2. Read and write data from/to the socket
3. Flush and close the socket
5. Close the socket (`ServerSocket`)
### Server structure and methods

In order to create a server, the following workflow is followed:

> 1. Create a socket (class `ServerSocket`)
> 2. Bind the socket to an IP address and a port number
> 3. Listen for incoming connections
> 4. Loop
> 1. Accept an incoming connection - creates a new socket (class `Socket`) on
> a random port number
> 2. Read and write data from/to the socket
> 3. Flush and close the socket
> 5. Close the socket (`ServerSocket`)
The available methods are the following:

| Operation | Description |
| ---------- | ------------------------------------------------- |
Expand Down
2 changes: 1 addition & 1 deletion 13-java-tcp-programming/PRESENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,4 @@ You will start the practical work!
- Illustration by [James Elchico](https://unsplash.com/@jdelchico) on
[Unsplash](https://unsplash.com/photos/blue-and-brown-padded-chairs-near-table-zB4A-PP49ww)
- Illustration by [micheile henderson](https://unsplash.com/@micheile) on
[Unsplash](https://unsplash.com/photos/woman-selling-inside-store-during-daytime-7NFwwp-vZk8)
[Unsplash](https://unsplash.com/photos/woman-selling-inside-store-during-daytime-7NFwwp-vZk8)

0 comments on commit 30be65e

Please sign in to comment.