Aim
To write a java
program for application using TCPSockets Links
Algorithm
1.Start the program.
2.Get the frame size
from the user
3.To
create the framebased on the user request.
4.To
send frames to server from the client side.
5.If your frames
reach the server it will send ACK signal to client otherwise it will
send NACK signal to client.
6.Stop the program
EchoServer.java
import
java.net.*;
import
java.io.*;
public
class EServer
{
public
static void main(String args[])
{
ServerSocket
s=null;
String
line;
DataInputStream
is;
PrintStream
ps;
Socket
c=null;
try
{
s=new
ServerSocket(9000);
}
catch(IOException
e)
{
System.out.println(e);
}
try
{
c=s.accept();
is=new
DataInputStream(c.getInputStream());
ps=new
PrintStream(c.getOutputStream());
while(true)
{
line=is.readLine();
ps.println(line);
}
}
catch(IOException
e)
{
System.out.println(e);
}
}
}
EClient.java
import
java.net.*;
import
java.io.*;
public
class EClient
{
public
static void main(String arg[])
{
Socket
c=null;
String
line;
DataInputStream
is,is1;
PrintStream
os;
try
{
InetAddress
ia = InetAddress.getLocalHost();
c=new
Socket(ia,9000);
}
catch(IOException
e)
{
System.out.println(e);
}
try
{
os=new
PrintStream(c.getOutputStream());
is=new
DataInputStream(System.in);
is1=new
DataInputStream(c.getInputStream());
while(true)
{
System.out.println("Client:");
line=is.readLine();
os.println(line);
System.out.println("Server:"
+ is1.readLine());
}}
catch(IOException
e)
{
System.out.println("Socket
Closed!");
}
}
}
Output
Server
C:\Program
Files\Java\jdk1.5.0\bin>javac EServer.java
Note:
EServer.java uses or overrides a deprecated API.
Note:
Recompile with -deprecation for details.
C:\Program
Files\Java\jdk1.5.0\bin>java EServer
C:\Program
Files\Java\jdk1.5.0\bin>
Client
C:\Program
Files\Java\jdk1.5.0\bin>javac EClient.java
Note:
EClient.java uses or overrides a deprecated API.
Note:
Recompile with -deprecation for details.
C:\Program
Files\Java\jdk1.5.0\bin>java EClient
Client:
Hai
Server
Server:Hai
Server
Client:
Hello
Server:Hello
Client:
end
Server:end
Client:
ds
Socket
Closed!
No comments:
Post a Comment