Running a program in Java about slidsender and slidreceiver with a brief explanation what each one is doing.
slidreceiver
import java.net.*; import java.io.*; class slidreceiver
{
public static void main(String a[])throws Exception
{
Socket s=new Socket(InetAddress.getLocalHost(),10); DataInputStream in=new
DataInputStream(s.getInputStream()); PrintStream p=new
PrintStream(s.getOutputStream());
int i=0,rptr=-1,nf,rws=8; String rbuf[]=new String[8]; String ch;
System.out.println(); do
{
nf=Integer.parseInt(in.readLine()); if(nf<=rws-1)
{
for(i=1;i<=nf;i++)
{
rptr=++rptr%8; rbuf[rptr]=in.readLine();
System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]);
}
rws-=nf; System.out.println("\nAcknowledgment sent\n"); p.println(rptr+1);
rws+=nf; }
else break;
ch=in.readLine();
}
while(ch.equals("yes"));
}
}
slidsender
| import java.net.*; |
| import java.io.*; |
| import java.rmi.*; |
| public class slidsender |
| { |
| public static void main(String a[]) throws Exception |
| { |
| ServerSocket ser=new ServerSocket(1024); |
| Socket s=ser.accept(); |
| DataInputStream in=new DataInputStream(System.in); |
| DataInputStream in1=new DataInputStream(s.getInputStream()); |
| String sbuff[]=new String[8]; |
| PrintStream p; |
| int sptr=0,sws=8,nf,ano,i; |
| String ch; |
| do |
| { |
| p=new PrintStream(s.getOutputStream()); |
| System.out.print("Enter the no. of frames : "); |
| nf=Integer.parseInt(in.readLine()); |
| p.println(nf); |
| if(nf<=sws-1) { |
| System.out.println("Enter "+nf+" Messages to be send\n"); |
| for(i=1;i<=nf;i++) { |
| sbuff[sptr]=in.readLine(); |
| p.println(sbuff[sptr]); |
| sptr=++sptr%8;} sws-=nf; |
| System.out.print("Acknowledgment received"); |
| ano=Integer.parseInt(in1.readLine()); |
| System.out.println(" for "+ano+" frames"); sws+=nf; |
| } else |
| { |
| System.out.println("The no. of frames exceeds window size"); |
| break; |
| } |
| System.out.print("\nDo you wants to send some more frames : "); |
| ch=in.readLine(); |
| p.println(ch); |
| } |
| while(ch.equals("yes")); |
| s.close(); |
| } |
}
The above program is written to explain the messaging technique over computer network. Here the two classes 'slidsender' and 'slidreceiver' are the two nodes of communication.
Slidsender:
The slidsender is the node who is initiating the communication by sending a predefined window of bytes of information to the receiver. The window size is already defined and if the message increases the window size then it throws the error that the frames exxeed the window size. Also it has a process of receiving acknowledgment from the other node to ensure the message has been received properly by the receiver node. After one complete delivery, the program asks the sender if he wants to send more frames of information. Depending upon the choice the program continues or aborts.
Slidreceiver:
The slidreceiver is the node who is on the other side of the network, receiving message from the slidsender. After the connection is established between the two nodes, the frames containing sensitive information starts to pass through the network. The slidreceiver, being on the other end receives the message. Once one window frame is completely received, the slidreceiver sends an acknowledgement byte to let the slidsender know that the frame has been properly received.
Due to network congestion or traffic, it may sometime happen that the frames containing sensitive information may not get sent completely and some bytes get missing. Therefore, the acknowledgment byte plays a very important role to let both the parties know that the communication was successful and the data has reached from one side to another safely.
Running a program in Java about slidsender and slidreceiver with a brief explanation what each one...
Using java socket programming rewrite the following program to handle multiple clients simultaneously (multi threaded programming) import java.io.*; import java.net.*; public class WelcomeClient { public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println( "Usage: java EchoClient <host name> <port number>"); System.exit(1); } String hostName = args[0]; int portNumber = Integer.parseInt(args[1]); try ( Socket kkSocket = new Socket(hostName, portNumber); PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true); BufferedReader in = new BufferedReader( new InputStreamReader(kkSocket.getInputStream())); ) { BufferedReader...
I need help with my IM (instant messaging) java program, I created the Server, Client, and Message class. I somehow can't get both the server and client to message to each other. I am at a roadblock. Here is the question below. Create an IM (instant messaging) java program so that client and server communicate via serialized objects (e.g. of type Message). Each Message object encapsulates the name of the sender and the response typed by the sender. You may...
Error: Main method not found in class ServiceProvider, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application This is the error im getting while executing the following code Can you modify the error import java.net.*; import java.io.*; public class ServiceProvider extends Thread { //initialize socket and input stream private Socket socket = null; private ServerSocket server = null; private DataInputStream in = null; private DataOutputStream out = null; private int...
please help. About java tcp. this is what i have so far. how to convert input value into ASCII sequence For example the message: “Hello World” would become “Ifmmp!Xpsme”For example the message: “Hello World” would become “Ifmmp!Xpsme”in server.java. Client.java: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.Socket; import java.net.SocketTimeoutException; public class Client { public static void main(String[] args) throws IOException { Socket client = new Socket("127.0.0.1", 20006); client.setSoTimeout(10000); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); PrintStream out...
The DictionaryClient program featured in the class lecture also used the try-catch when creating a socket. Socket are auto-closeable and thus can use a try-with-resources instead. Edit the dictionary program to use try-with-resources instead. package MySockets; import java.net.*; import java.io.*; public class DictionaryClient { private static final String SERVER = "dict.org"; private static final int PORT = 2628; private static final int TIMEOUT = 15000; public static void main(String[] args) { Socket ...
Q7 The following Client side Java code can send a message to the server side via UDP socket. The client side Java code and the server side Java code are running in two different hosts respectively. The server side host name is “MyFileServer”. The server side receives the message and converts all the letters in the message received to uppercase, then sends the modified message back to the client side. Please read the code carefully, and fill out the blanks...
The following Client side Java code can send a message to the server side via UDP socket. The client side Java code and the server side Java code are running in two different hosts respectively. The server side host name is “MyFileServer”. The server side receives the message and converts all the letters in the message received to uppercase, then sends the modified message back to the client side. Please read the code carefully, and fill out the blanks with...
1. Create two directories from a DOS or Unix prompt. Name one directory 'RMILabServer' and the other directory 'RMILabClient'. 2. Within the server directory, save the following three classes. //************************************************************ // Calculator.java Interface for a Calculator import java.rmi.*; public interface Calculator extends Remote { // this method will be called from remote clients int add (int x, int y) throws RemoteException; } //************************************************************* // CalculatorServant.java // A Remote object class that implements Calculator. import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class CalculatorServant...
Java Any help is appreciated 8.What is the output of the following program? import java.io.*; public class Q8 { public static void main (String [] args)throws IOException { RandomAccessFile file = new RandomAccessFile (new File ("Q8.txt"), "rw"); double x = 100.00 ; file.writeDouble(x); file.writeDouble(x+10); file.writeDouble(x+20); file.seek(8); System.out.println(file.readDouble()); System.out.println(file.getFilePointer()); } } -------------------------------------------- Output 110.00 16 My Question: why is this the output?