NP Lab PDF
NP Lab PDF
NP Lab PDF
An iterative server handles both the connection request and the transaction involved in
the call itself. Iterative servers are fairly simple and are suitable for transactions that do
not last long.
Output - server.java
$ java server.java
Server Started and listening to the port 25000
Message received from client is Saurav
Message sent to the client is Hello Saurav !!
Output - client.java
$ java client.java
Message sent to the server : Saurav
Message received from the server : Hello Saurav !!
2. Write an echo program with client and concurrent server using TCP.
A concurrent server -
Output - server.java
$ java server.java
message = hello from client1
message = hello from client2
message = bye
message = bye
Output - client1
$ java client.java
hello from client1
bye
Output - client
$ java client.java
hello from client2
bye
3. Write an echo program with client and concurrent server using UDP.
Output - server.java
$ sudo java server.java
Received from: /127.0.0.1:52391
Received from: /127.0.0.1:46293
Output - client1
$ java client.java
hello from client1
Output - client2
$ java client.java
hello from client2
outStream.write(typedMessage.getBytes("UTF-8"));
sleep(100);
}
};
}
catch(IOException i){
i.printStackTrace();
}
catch(InterruptedException ie){
ie.printStackTrace();
}
}
}
};
writeThread.setPriority(Thread.MAX_PRIORITY);
writeThread.start();
}
public static void main(String[] args)throws Exception{
ChatSocketClient myChatClient = new ChatSocketClient();
myChatClient.createSocket();
}
}
Output - server.java
$ java server.java
Connected
Client :hi
hello
Client :how are you?
i'm fine. what about you?
Client :i’m also fine
Output - client.java
$ java client.java
Connected
hi
Server :hello
how are you?
Server :I'm fine. what about you?
i’m also fine
5. Write a program to retrieve date and time using TCP.
Output - server.java
$ java server.java
Output - client.java
$ java client.java
Thu Oct 08 07:08:02 UTC 2020
Output - server.java
$ sudo java server.java
Received from: /127.0.0.1:36208
Output - client.java
$ java client.java
Thu Oct 08 07:20:13 UTC 2020
Output - server.java
$ java server.java
i'm a server and i'm waiting for new connection and buffer select...
Connection Accepted: /127.0.0.1:1111
i'm a server and i'm waiting for new connection and buffer select...
Message received: Facebook
i'm a server and i'm waiting for new connection and buffer select...
Message received: Twitter
i'm a server and i'm waiting for new connection and buffer select...
Message received: IBM
i'm a server and i'm waiting for new connection and buffer select...
Message received: Google
i'm a server and i'm waiting for new connection and buffer select...
Message received: Crunchify
It's time to close connection as we got last company name 'Crunchify'
Server will keep running. Try running client again to establish new connection
i'm a server and i'm waiting for new connection and buffer select...
Output - client.java
$ java client.java
Connecting to Server on port 1111...
sending: Facebook
sending: Twitter
sending: IBM
sending: Google
sending: Crunchify
Output - server.c
$ gcc server.c -o server
$ ./server
Line recieved from the client :hi
Line recieved from the client :hello
Line recieved from the client :i'm saurav
Output - client.c
$ gcc client.c -o client
$ ./client 2
Enter data to be send : hi
Line send to server is : hi
Line recieved from the server : HI
hello
Line send to server is : hello
Line recieved from the server : HELLO
i'm saurav
Line send to server is : i'm saurav
Line recieved from the server : I'M SAURAV
9. Write an echo client and server program using Unix domain stream
socket.
Output - server.c
$ gcc server.c -o server
$ ./server
TCPServer Waiting for client on port 5000
I got a connection from (127.0.0.1 , 39112)
Output - client.c
$ gcc client.c -o client
$ ./client
Received data = Hello User!!
10. Write an echo client and server program using Unix domain
Datagram socket.
Output - server.c
$ gcc server.c -o server
$ ./server
UDPServer Waiting for client on port 5000
(127.0.0.1 , 48905) said : hi
Output - client.c
$ gcc client.c -o client
$ ./client
Type Something :hi
Output - server.java
$ java server.java
Waiting for client
Sending file data to client
Sent file successfully to client
Waiting for client
Output - client.java
$ java client.java
Connected to server
Receiving file
File Copied Successfully
Output - server.java
$ java server.java
Server Started and listening to the port 25000
Command received from client is : $ ls
Command output : $ client.java
server.java
Output - client.java
$ java client.java
Command sent to the server : ls
client.java
server.java
Command output received from the server :
null
13. Write a client program that gets a number from the user and sends
the number to the server for conversion into hexadecimal and gets
the result from the server.
Output - server.java
$ java server.java
hexadecimal value of user input = 20
$ java server.java
hexadecimal value of user input = 23
Output - client.java
$ java client.java
32
$ java client.java
35