How to check my server socket programs are correct...?
Just started to read about socket programming.I have written a simple program for reading a file from server and write in client side.
Check this,
For server side....
import java.io.*;
import java.net.*;
public class ss
{
public static void main(String args[])
{
byte b[]=new byte[60];
try
{
ServerSocket s=new ServerSocket(12345);
Socket s1=s.accept();
File f=new File("kk.txt");
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(f));
bis.read(b);
OutputStream os=s1.getOutputStream();
os.write(b);
s1.close();
}
catch(Exception e)
{
System.out.println("Exception caught ");
}
}
}
For client side....
import java.io.*;
import java.net.*;
public class ss
{
public static void main(String args[])
{
byte b[]=new byte[60];
try
{
Socket s=new Socket("27.0.0.1",1234);
InputStream is=s.getInputStream();
is.read(b);
FileOutputStream f=new FileOutputStream("monu.txt");
BufferedOutputStream bos=new BufferedOutputStream(f);
bos.write(b);
bos.close();
s.close();
}
catch(Exception e)
{
System.out.println("Exception caught ");
}
}
}
But the problem is that i want to check that my program working fine or not but i don't know how can i check this.Can i use any hosting account as a server ?
If yes then what to do in order to execute this program ?