0% found this document useful (0 votes)
22 views

Server

The document describes a Java program that implements a server socket to communicate with a client over a network. The server accepts connection requests, reads input from the client, and sends acknowledgments back to the client. It uses buffers and windows to manage message frames being sent between the client and server.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Server

The document describes a Java program that implements a server socket to communicate with a client over a network. The server accepts connection requests, reads input from the client, and sends acknowledgments back to the client. It uses buffers and windows to manage message frames being sent between the client and server.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.net.

*;
import java.io.*;
import java.rmi.*;
public class Server
{
public static void main(String args[])throws Exception
{
ServerSocket ser=new ServerSocket(10);
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 theno 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.println("Acknowledgement 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.println("\n doyou want to send some more frames:");
ch=in.readLine();
p.println(ch);
}
while(ch.equals("yes"));
s.close();
}
}

You might also like