Transferencia Archivos
Hola estoy tratando de enviar un archivo por sockets, pero no se como hacer para q el cleinte "arme" el archivo, es decir d los bytes q va leyendo vaya poniendolos en un archivo nuevo este es mi codigo la vdd no lo he probado pero espero alguien m poeda ayudar :
import java.io.*;
class serv
{
java.net.ServerSocket ser;
public serv()
{ try
{
ser = new java.net.ServerSocket(5000);
}
catch(Exception o)
{
}
}
public void execute ()
{ try
{
while(true)
new client(ser.accept()).run();
}
catch (Exception o)
{
}
}
public static void main(String [] args )
{
serv s = new serv();
s.execute();
}
public class client extends Thread
{ java.net.Socket s ;
java.io.DataInputStream is;
java.io.DataOutputStream out;
byte dat;
public client(java.net.Socket s)
{ try
{
this.s = s;
is = new java.io.DataInputStream(new java.io.FileInputStream("EOF.java"));
out = new java.io.DataOutputStream(s.getOutputStream());
send();
}
catch (Exception o)
{
}
}
public void send()
{
while(true)
{ try
{
dat = is.readByte();
out.writeByte(dat);
}
catch (Exception o){
}
}
}
}
}
//Clase cliente, esta clase esta incompleta por la duda
//q tengo :p
import java.io.*;
import java.net.*;
class client
{
Socket s;
DataInputStream read;
public client ()
{
public s = new Socket ("127.0.0.1",5000);
byte b ;
read = new DataInputStream (s.getInputStream());
FileInputStream d =
while(b != null)
{
b = read.readByte();
}
}
}
Agradecaria cualquier ayuda
import java.io.*;
class serv
{
java.net.ServerSocket ser;
public serv()
{ try
{
ser = new java.net.ServerSocket(5000);
}
catch(Exception o)
{
}
}
public void execute ()
{ try
{
while(true)
new client(ser.accept()).run();
}
catch (Exception o)
{
}
}
public static void main(String [] args )
{
serv s = new serv();
s.execute();
}
public class client extends Thread
{ java.net.Socket s ;
java.io.DataInputStream is;
java.io.DataOutputStream out;
byte dat;
public client(java.net.Socket s)
{ try
{
this.s = s;
is = new java.io.DataInputStream(new java.io.FileInputStream("EOF.java"));
out = new java.io.DataOutputStream(s.getOutputStream());
send();
}
catch (Exception o)
{
}
}
public void send()
{
while(true)
{ try
{
dat = is.readByte();
out.writeByte(dat);
}
catch (Exception o){
}
}
}
}
}
//Clase cliente, esta clase esta incompleta por la duda
//q tengo :p
import java.io.*;
import java.net.*;
class client
{
Socket s;
DataInputStream read;
public client ()
{
public s = new Socket ("127.0.0.1",5000);
byte b ;
read = new DataInputStream (s.getInputStream());
FileInputStream d =
while(b != null)
{
b = read.readByte();
}
}
}
Agradecaria cualquier ayuda
