Servidor
Código:
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class Servidor
implements Runnable
{
ServerSocket server;
Socket connection;
DataOutputStream output;
BufferedInputStream bis;
BufferedOutputStream bos;
byte receivedData[];
int in;
String file;
String file1;
String file2;
public Servidor()
{
connection = null;
try
{
server = new ServerSocket(1234);
System.out.println("serveur");
}
catch(Exception e)
{
System.out.println((new StringBuilder("erreur serveurn")).append(e).toString());
System.exit(1);
}
}
public void run()
{
Socket client = null;
do
{
do
{
if(server == null)
{
return;
}
try
{
client = server.accept();
System.out.println("nuevo cliente");
}
catch(IOException e)
{
System.err.println((new StringBuilder("connexion impossible")).append(e.getMessage()).toString());
}
} while(server == null);
try
{
InputStream in = client.getInputStream();
DataInputStream dis = new DataInputStream(client.getInputStream());
file = dis.readUTF();
file1 = dis.readUTF();
file2=dis.readUTF();
int i=dis.readInt();
if(i==1)
{
File directorio = new File("c:\\directorio\\"+file1+"\\"+file2+"\\");
directorio.mkdir();
}
if(file != null)
{
bos = new BufferedOutputStream(new FileOutputStream("C:\\directorio\\"+file1+"\\"+file2+"\\"+ file));
byte buf[] = new byte[1024];
int len;
while((len = in.read(buf)) > 0)
{
bos.write(buf, 0, len);
}
// in.close();
bos.close();
}
}
catch(IOException e)
{
System.out.println((new StringBuilder("Error: ")).append(e).toString());
}
} while(true);
}
public static void main(String a[])
{
Servidor servidor = new Servidor();
(new Thread(servidor)).start();
}
}
gracias todos.