Professional Documents
Culture Documents
1) Use Connection-Oriented and Connectionless Sockets To Implement A Basic File Transfer Protocol (FTP)
1) Use Connection-Oriented and Connectionless Sockets To Implement A Basic File Transfer Protocol (FTP)
AIM:
To implement a simple file transfer protocol (FTP) using connection-oriented and connectionless sockets.
PROCEDURE:
FileServer
FileClient
FlowChart :
Page 1
CN TERMINAL LAB GOPINATH K S 19IT030
CODE :
Server :
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
try
ss = new ServerSocket(port);
Page 2
CN TERMINAL LAB GOPINATH K S 19IT030
catch (IOException e)
e.printStackTrace();
while (true)
try
saveFile(clientSock);
catch (IOException e)
e.printStackTrace();
Page 3
CN TERMINAL LAB GOPINATH K S 19IT030
int read = 0;
int totalRead = 0;
totalRead += read;
remaining -= read;
fos.write(buffer, 0, read);
fos.close();
dis.close();
fs.start();
Client :
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
Page 4
CN TERMINAL LAB GOPINATH K S 19IT030
import java.net.Socket;
private Socket s;
try
sendFile(file);
catch (Exception e)
e.printStackTrace();
dos.write(buffer);
Page 5
CN TERMINAL LAB GOPINATH K S 19IT030
System.out.println("File sent...");
fis.close();
dos.close();
OUTPUT SCREENSHOTS:
Page 6
CN TERMINAL LAB GOPINATH K S 19IT030
RESULT:
Thus an application for the File transfer from the server to the client has been implemented and verified.
Page 7
CN TERMINAL LAB GOPINATH K S 19IT030
AIM:
To implement a remote service request-response application using Remote Method Invocation (RMI)
in Java for a hospital’s outpatient enrollment system.
PROCEDURE:
MyClient.java
➢ Import the package for remote method invocation and the util. package.
➢ Provide the lookup option in Naming to the method.
➢ Declare the variables.
➢ Get Voter ID from the user.
➢ Pass the voter ID entered by the user to the checkvote method to verify the voter ID using stub.
➢ Handle the returned values appropriately to the applicable conditions.
➢ When verified get the choice of selection to vote from the user
➢ Pass it to another method using instance of Vote in the method called vote().
➢ Appropriately handle the returned values.
➢ Get authorized password for verification and pass it to checkresult() method.
➢ Appropriately handle the returned values.
➢ Handle exceptions caused using try catch block.
➢ End.
MyServer.java
Page 8
CN TERMINAL LAB GOPINATH K S 19IT030
Flowchart:
CODE :
Adder –
import java.rmi.*;
AdderRemote:
import java.rmi.*;
import java.rmi.server.*;
{
Page 9
CN TERMINAL LAB GOPINATH K S 19IT030
AdderRemote()throws RemoteException
super();
return x+y+z;
MyClient:
import java.rmi.*;
try
Adder stub=(Adder)Naming.lookup("rmi://localhost:5000/sonoo");
System.out.println("AGE : 22");
System.out.println("TYPE : OP");
System.out.println("TOTAL : "+stub.add(2000,1500,100));
Page 10
CN TERMINAL LAB GOPINATH K S 19IT030
catch(Exception e){}
MyServer:
import java.rmi.*;
import java.rmi.registry.*;
try
catch(Exception e)
System.out.println(e);
Page 11
CN TERMINAL LAB GOPINATH K S 19IT030
OUTPUT SCREENSHOTS:
Server :
Client:
Page 12
CN TERMINAL LAB GOPINATH K S 19IT030
RESULT :
Thus, we have successfully implemented a remote service request-response application using Remote
Method Invocation (RMI) in Java for for a hospital’s outpatient enrollment system.
Page 13