hi,
i just want 2 communicate with the near by computer. i got this program from internet. i have two programs called Server.java and Client.java.
i am putting that program here now,
Server.java Program:
import java.net.*;
import java.io.*;
public class Server
{
public static void main(String[] args) throws IOException{
Socket client= null;
PrintWriter pout=null;
ServerSocket sock=null;
try{
sock= new ServerSocket(51 55);
// now listen for connections
while(true){
client= sock.accept();
// we have a connection
pout = new PrintWriter(cli ent.getOutputSt ream(), true);
// write the date to the socket
pout.println(ne w java.util.Date( ).toString());
pout.close();
client.close();
}
}
catch (IOException ioe) {
System.err.prin tln(ioe);
}
finally {
if (client !=null)
client.close();
if (sock !=null)
sock.close();
}
}
Client.java Program:
import java.net.*;
import java.io.*;
public class Client
{
public static void main(String[] args) throws IOException{
InputStream in = null;
BufferedReader bin = null;
Socket sock = null;
try {
// make connection to socket
sock = new Socket("127.0.0 .1",5155);
in = sock.getInputSt ream();
bin = new BufferedReader( new InputStreamRead er(in));
String line;
while ((line= bin.readLine()) !=null)
System.out.prin tln(line);
}
catch (IOException ioe) {
System.err.prin tln(ioe);
}
finally{
if (sock !=null)
sock.close();
}
}
}
tell me wat shud i change in this program?
is it correct doing this?
Help me in doing this?
its urgent
}
i just want 2 communicate with the near by computer. i got this program from internet. i have two programs called Server.java and Client.java.
i am putting that program here now,
Server.java Program:
import java.net.*;
import java.io.*;
public class Server
{
public static void main(String[] args) throws IOException{
Socket client= null;
PrintWriter pout=null;
ServerSocket sock=null;
try{
sock= new ServerSocket(51 55);
// now listen for connections
while(true){
client= sock.accept();
// we have a connection
pout = new PrintWriter(cli ent.getOutputSt ream(), true);
// write the date to the socket
pout.println(ne w java.util.Date( ).toString());
pout.close();
client.close();
}
}
catch (IOException ioe) {
System.err.prin tln(ioe);
}
finally {
if (client !=null)
client.close();
if (sock !=null)
sock.close();
}
}
Client.java Program:
import java.net.*;
import java.io.*;
public class Client
{
public static void main(String[] args) throws IOException{
InputStream in = null;
BufferedReader bin = null;
Socket sock = null;
try {
// make connection to socket
sock = new Socket("127.0.0 .1",5155);
in = sock.getInputSt ream();
bin = new BufferedReader( new InputStreamRead er(in));
String line;
while ((line= bin.readLine()) !=null)
System.out.prin tln(line);
}
catch (IOException ioe) {
System.err.prin tln(ioe);
}
finally{
if (sock !=null)
sock.close();
}
}
}
tell me wat shud i change in this program?
is it correct doing this?
Help me in doing this?
its urgent
}
Comment