0% found this document useful (0 votes)
3 views1 page

Sender

The Java program 'Sender' establishes a connection to a server and allows the user to send a specified number of frames with messages. It prompts the user for the number of frames and the messages to be sent, then sends each message to the server while waiting for an acknowledgment. If no frames are specified, it informs the user that no frames will be sent.

Uploaded by

salhamussa2001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Sender

The Java program 'Sender' establishes a connection to a server and allows the user to send a specified number of frames with messages. It prompts the user for the number of frames and the messages to be sent, then sends each message to the server while waiting for an acknowledgment. If no frames are specified, it informs the user that no frames will be sent.

Uploaded by

salhamussa2001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.io.

*;
import java.net.*;
import java.util.Scanner;
public class Sender {
public static void main(String args[])
{
int p=9000,i,q=8000;
String h="localhost";
try
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter number of frames : ");
int number = scanner.nextInt();
if(number==0)
{
System.out.println("No frame is sent");
}
else
{
Socket s2;
s2= new Socket(h,q);
DataOutputStream d1 = new DataOutputStream(s2.getOutputStream());
d1.write(number);
}
String str1;
for (i=0;i<number;i++)
{
System.out.print("Enter message : ");
String name = scanner.next();
System.out.println("Frame " + i+" is sent");
Socket s1;
s1= new Socket(h,p+i);
DataOutputStream d = new DataOutputStream(s1.getOutputStream());
d.writeUTF(name);
DataInputStream dd= new DataInputStream(s1.getInputStream());
Integer sss1 = dd.read();
System.out.println("Ack for :" + sss1 + " is received");
}
}
catch(Exception ex)
{
System.out.println("ERROR :"+ex);
}
}
}

You might also like