Unit 2
Unit 2
SOCKET
Sockets in Java are used for communication between two computers over a
network. It allows one machine (the server) to listen for connections and
another machine (the client) to connect to it.
SECURE SOCKET
A **Secure Socket** ensures safe communication between two
computers over a network by encrypting the data exchanged.
This makes it difficult for hackers to intercept or alter the
information. Secure sockets use **SSL (Secure Sockets Layer)** or
**TLS (Transport Layer Security)** protocols to provide encryption,
authentication, and data integrity.
Can we call the run() method instead of start()?
What is Synchronization?
In Java, synchronization is like a traffic light for threads. It ensures
that only one thread can access a shared resource (like a variable,
object, or method) at a time, preventing chaos and ensuring
everything works correctly.
Definition in Java:
Synchronization in Java is a mechanism to control access to
shared resources in a multi-threaded environment. It prevents
thread interference and consistency issues by allowing only one
thread to access a synchronized block or method at a time.
1. **What is a Socket?**
- **UDP (User Datagram Protocol):** Faster but less reliable, used for
sending packets.
3. **How it works:**
- **Server Side:**
- **Client Side:**
- **Server:**
```
Client connected!
```
- **Client:**
```
```
SECURE SOCKET
A **Secure Socket** ensures safe communication between two
computers over a network by encrypting the data exchanged.
This makes it difficult for hackers to intercept or alter the
information. Secure sockets use **SSL (Secure Sockets Layer)** or
**TLS (Transport Layer Security)** protocols to provide encryption,
authentication, and data integrity.
1. **Handshake Process:**
- The client and server exchange certificates to verify each other’s identity.
2. **Encryption:**
3. **Decryption:**
- **HTTPS (HTTP Secure):** Secure sockets are used in web browsers for
secure websites (e.g., online banking, shopping).
```bash
```
```
### Output:
- **Server:**
```
```
- **Client:**
```
```