School of Information Technology and Engineering
School of Information Technology and Engineering
School of Information Technology and Engineering
ENGINEERING
Program:
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Server
{
public static void main(String args[]) throws Exception
{
ServerSocket ss=new ServerSocket(7777); Socket s=ss.accept();
System.out.println("connected……. ");
DataInputStream din=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream()); int
r,i=0;
int n=din.readInt(); int a[]=new int[n];
System.out.println("data:"); int count=0;
System.out.println("Receiving Data….");
for(i=0;i<n;i++)
{
a[i]=din.readInt();
}
System.out.println("Data Received");
System.out.println("Sorting Data……….");
Arrays.sort(a); System.out.println("Data Sorted");
System.out.println("Sending Data………");
for(i=0;i<n;i++)
{
dout.writeInt(a[i]);
}
System.out.println("\nData Sent Successfully"); s.close();
ss.close();
}
}
Client:
import java.io.*;
import java.net.*;
import java.util.Scanner;
System.out.println("Connected to server");
for(int i=0;i<n;i++)
{
System.out.println("Data Sent");
for(int i=0;i<n;i++)
s.close();
OUTPUT:
Server:
Client
2. Write a TCP /IP socket programming where client sends messages and
server checks for Palindrome and displayed on server side
Server:
import java.io.*; import java.net.*;
Socket socket;
String str;
public Server2()
try{
while(true)
if(str.charAt(left)!=(str.charAt(right)))
flag=0; break;
else
left++;right--;
else
}catch (Exception e) { }
new ServerCode2();
Client:
import java.io.*;
import java.net.*;
Socket socket;
String str;
public ClientCode()
try{
while(true)
break;
socket.close();
}catch (Exception e) { }
new ClientCode();
OUTPUT:
Server:
Client:
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class server3
{
ServerSocket ss=new ServerSocket(7777); Socket s=ss.accept();
System.out.println("connected…….. ");
for(i=0;i<n;i++)
a[i]=din.readInt();
System.out.println("Sending Data…….");
for(i=0;i<n;i++)
dout.writeInt(a[i]);
ss.close();
}
Client:
import java.io.*;
import java.net.*;
import java.util.Scanner;
System.out.println("Connected to server");
for(int i=0;i<n;i++)
System.out.println("Data Sent");
DataInputStream din=new DataInputStream(s.getInputStream()); int r;
for(int i=0;i<n;i++)
s.close();
OUTPUT:
Server:
Client:
Server:
import java.net.*;
import java.io.*;
import java.util.*;
class DateServer
soc.close();
Client:
import java.io.*;
import java.net.*;
class DateClient
));
System.out.println(in.readLine());
}
OUTPUT:
Server:
Client:
Server:
import java.io.*;
import java.net.*;
class ChatServer
public static byte buf[] = new byte[1024]; public static int cport =
789,sport=790;
{
serversocket.receive(dp);
if(str.equals("STOP"))
{
System.out.println("Terminated..."); break;
}
}
Client:
import java.io.*;
import java.net.*;
class ChatClient
790;
buf.length);
InetAddress.getLocalHost();
if(str.equals("STOP"))
System.out.println("Terminated...");
clientsocket.receive(dp);
}
}
OUTPUT:
Server:
Client:
Server:
import java.io.*;
import java.net.*;
class Question6
System.out.println("connected..........");
int r;
while((r=fin.read())!=-1)
dout.write(r);
System.out.println("\nFiletranfer Completed");
Client:
import java.io.*;
import java.net.*;
if(s.isConnected())
System.out.println("Connected to server");
FileOutputStream fout;
int r;
while((r=din.read())!=-1)
fout.write((char)r);
OUTPUT:
Server:
Client:
Server:
import java.io.*;
import java.net.*;
try{
while (true) {
InputStreamReader(input));
String text;
do {
text = reader.readLine();
StringBuilder(text).reverse().toString();
} while (!text.equals("bye"));
socket.close();
}catch(IOException e){
}
}
Client:
import java.net.*;
import java.io.*;
/**
* @author Neeraj
*/
/**
*/
try{
String text;
do {
writer.println(text);
InputStreamReader(input));
System.out.println(time);
} while (!text.equals("bye"));
socket.close();
}catch(IOException e){
System.out.println(e);
}
OUTPUT:
Server:
Client:
try {
Socket socket = new Socket(hostName, portNumber);
PrintWriter out =
new PrintWriter(socket.getOutputStream(), true);
BufferedReader in =
new BufferedReader(
new InputStreamReader(socket.getInputStream()));
out.println("GET / HTTP/1.1\nHost: www.instagram.com\n\n");
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
} catch (UnknownHostException e) {
System.err.println("Don't know about host " + hostName);
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to " +
hostName);
System.exit(1);
}
}
}
OUTPUT:
9. The Academics office of VIT wishes to make the Registrations
more secured. If you are a Programmer how you will implement a
system to validate thelogin credentials obtained from the user
thereby denying them access to unauthorized users.
Server:
import java.net.*;
import java.io.*;
Out.writeUTF(line);
ss.close();
OUTPUT:
10. Implementa TCP/IPbased Serverprogramin Javatocompute
thefactorialofanumber(can contain arbitrary number of digits).
Write a client program to test the working of the same)
Server:
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.Socket;
String fname=br.readLine();
PrintStream dos=new PrintStream(s.getOutputStream());
dos.println(fname);
String sts=kb.readLine();
s.close();
OUTPUT:
Server:
Client: