TCP CLIENT
//tcpclient.java
import java.io.*;
import java.net.*;
public class tcpclient
{
public static void main(String[] args) throws IOException
{
System.out.println(“TCP CLIENT”);
System.out.println(“Enter the host name to connect”);
DataInputStream inp=new DataInputStream(System.in);
String str=inp.readLine();
Socket clientsoc = new Socket(str, 9);
PrintWriter out = new PrintWriter(clientsoc.getOutputStream(), true);
BufferedReader in = new BufferedReader(new
InputStreamReader(clientsoc.getInputStream()));
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String userinput;
try
{
while (true)
{
System.out.println(“Sever Says : ” + in.readLine());
userinput = stdin.readLine();
out.println(userinput);
}
}
catch(Exception e)
{
System.exit(0);
}
}
}
TCP SERVER
//tcpserver.java
import java.io.*;
import java.net.*;
public class tcpserver
{
public static void main(String a[]) throws Exception
{
System.out.println(“TCP SERVER”);
System.out.println(“Server is ready to connect…”);
ServerSocket serversoc=new ServerSocket(9);
Socket clientsoc = serversoc.accept();
PrintWriter out = new PrintWriter(clientsoc.getOutputStream(), true);
BufferedReader in = new BufferedReader(new
InputStreamReader(clientsoc.getInputStream()));
String inputline;
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
try
{
while (true)
{
inputline = stdin.readLine();
out.println(inputline);
System.out.println(“Client Says : “+in.readLine());
}
}
catch(Exception e)
{
System.exit(0);
}
}
}
Sample Output:
CLIENT-SERVER CHATTING USING TCP
*************************************
TCP SERVER
************
Server is ready to connect…
hello
Client Says : hello
How are you
Client Says : I’m doing programs
What programs
Client Says : networking
ok.Go ahead
Client Says : ok.Bye
Bye
TCP CLIENT
***********
Enter the host name to connect
p4-221
Sever Says : hello
hello
Sever Says : how are you
I’m doing programs
Sever Says : What programs
networking
Sever Says : ok.Go ahead
ok.Bye
Sever Says : Bye
after running server side it doesn’t take any input
I want to transfer a file in server to client.How to convert FileInputStream to
32
I want java applet program for client/server in lan.
even the client is not get connected ,the server send information.
when ever the client is get connection , then it will receieve the message and also it send reply…
many clients are mentioned using ip address
i want program for implement Remote Procedure Call and also i want program for simulate Domain Name Server
ok fine u r code ,but using this we can communicate with only one client.in the case of multiple clients and single server what we can change in the code please clarify this ,i need urgent
THANKS®ARDS
HARI
PH:9848985781
I want to download a file from server to client machine. What changes should be made to this pgm? Pls reply
Hi archana,if u have the code for downloading files from server to client, using socket,send me by mail on theloverboy014@yahoo.com
thks
after running server side it doesn’t take any input
Tell me correct reason
it doesnt work
very nice
gud program worked with out any issues.. but can any body plz expaline me the code… i mean like why we have used serversoc.accept(); and about such kind of statements…. ple reply to ravigold01@gmail.com
how to give host name?
Its very helpfulll