how to send files through sockets
I'm developing a program and I need to send files through sockets
I'm using BufferInputStream,DataInputStream.
I choose some file from server and then send it to the client.
The client receives it but it doesn't open!
I send you my code
In server I do something like that:
Code:
public class Server
{
static final int Port=5000;
public int nClients=0;
private String file="./files/3.jpg";
/** Creates a new instance of server*/
public Server()
{
try
{
ServerSocket serverSock=new ServerSocket(Port);
System.out.println( Port);
while(true)
{
serverSock.accept();
Socket cliente=serverSock.accept();
nClients++;
System.out.println(nClients);
SClient(client,nClients);
SocketThread thread=new SocketThread
(client,file,nClients-1);
hilo.start();
}
}
catch(Exception ex)
{
System.out.println(ex);
}
}
In the client I do that:
Code:
DataInputStream en = new DataInputStream
(skClient.getInputStream());
byte buffer[] = new byte[breaden];
//breaden=en.read(buffer);
File rec=new File("./rec/1.jpg");
rec.setReadable(true);
rec.setWritable(true);
//FileOutputStream f=new FileOutputStream(rec);
FileOutputStream f=new FileOutputStream
("./rec/1.jpg");
f.write(buffer);
skClient.close();
Sending files through sockets
Anyone know where I can access a complete tutorial on how to send files through java sockets? If so, please tell me where, I'd be glad to receive any references. Thanks in advance!!!!:)