View Single Post
  #3 (permalink)  
Old 05-14-2008, 10:33 AM
rameshraj rameshraj is offline
Member
 
Join Date: Dec 2007
Posts: 38
rameshraj is on a distinguished road
public static void main(String[] args) throws Exception {
Thread serverthread = new Thread(new Runnable(){
public void run(){
ServerSocket ss = null;
try{

ss = new ServerSocket(44444);

Socket s = ss.accept();

OutputStream out = s.getOutputStream();
FileInputStream fin = new FileInputStream("Test.txt");
byte[] buf = new byte[1024];
int read;
while( (read=fin.read(buf)) != -1) {
out.write(buf, 0, read);

}..................................




I am using the above concept to read the file in a Stream and sending it to the OutputStream.
On the other side I am receiving similarly in a loop and saving it to a file:

String f2="E:/E-resources/java/Test.txt";
FileOutputStream fos = new FileOutputStream(new File(f2));

while(in.read(buf)!=-1)
{
fos.write(buf);
System.out.println("Writing to the file is\t"+buf[29]+".."+fos.getChannel().size());
}
.........................


Using this technique how can I distinguish the two(ordinary message and File Transfers).
Reply With Quote