Client Side
Would you like to make this site your homepage? It's fast and easy...
Yes, Please make this my home page!
/*
Author:ZT
Date: Sep 30,3017
*/
/*
this program act as a client Sending data to
a server on anothor node with ip address xxx.yyy.zzz.aaa and port no ii
on
1- SEVER SIDE start for example :java Server1 66
where 66 is the prot number
now the server1 program waiting for incoming messages from the Client on the other node
2- Client Side start for example : java Client1 161.162.64.2 66
where the IpAddress of the Server is 161.162.64.2 and talk to the same port started
on the Server side
*/
package a.b.c;
// File Name GreetingClient.java
import java.net.*;
import java.io.*;
public class GreetingClient {
static String mymessage=" ";
public static void main(String [] args) {
String serverName = args[0];
String mymessage=args[2];
int port = Integer.parseInt(args[1]);
try {
File f1=new File("message.txt");
FileInputStream fis=new FileInputStream(f1);
BufferedReader br=new BufferedReader(new InputStreamReader(fis));
String line=null;
System.out.println("Connecting to " + serverName + " on port " + port);
// line=br.readLine();
while((line=br.readLine()) !=null){
Socket client = new Socket(serverName, port);
// System.out.println("Just connected to " + client.getRemoteSocketAddress());
OutputStream outToServer = client.getOutputStream();
DataOutputStream out = new DataOutputStream(outToServer);
// System.out.println(line);
// out.writeUTF(line + client.getLocalSocketAddress());
out.writeUTF(line ) ; // + client.getLocalSocketAddress());
//InputStream inFromServer = client.getInputStream();
//DataInputStream in = new DataInputStream(inFromServer);
// System.out.println("Server says " + in.readUTF());
client.close();
} // end of while
br.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}