0% found this document useful (0 votes)
5 views3 pages

Prog 5

Uploaded by

22ita58
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Prog 5

Uploaded by

22ita58
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

721222205019

PROGRAM:
import

javax.net.ssl.*; import java.io.*;

import java.security.*; public

class Server {

public static

void main(String[] args) {

try {

SSLServerSocketFactory

serverSocketFactory = (SSLServerSocketFactory)

SSLServerSocketFactory.getDefault();

SSLServerSocket

serverSocket = (SSLServerSocket)

serverSocketFactory.createServerSocket(9999);

SSLSocket

sslSocket = (SSLSocket) serverSocket.accept();

// Read data from client

BufferedReader

input = new BufferedReader(new


InputStreamReader(sslSocket.getInputStream())); String
721222205019
clientMessage = input.readLine();

System.out.println("Received from client: " + clientMessage);

// Close

streams and socket

input.close(); sslSocket.close(); serverSocket.close();

} catch

(IOException e) { e.printStackTrace();

**Client:**

import

javax.net.ssl.*; import java.io.*; import java.security.*; public

class Client {

public static

void main(String[] args) { try {

SSLSocketFactory

sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();

SSLSocket sslSocket = (SSLSocket)


sslSocketFactory.createSocket("localhost", 9999);
721222205019
// Send data to server

PrintWriter

output = new PrintWriter(sslSocket.getOutputStream(), true);


output.println("Hello, server!");

// Close streams and socket output.close(); sslSocket.close();

} catch

(IOException e) { e.printStackTrace();

You might also like