i'm trying to make a server client program in java. I'm trying to run on same system. It sends a text file from client to server including names etc. But when the server gets the file it just prints "[]" characters. Does that mean null or does that mean corrupted data?
Here is the server;
package temel;
import java.io.File;
import java.io.InputStream;
import java.net.Socket;
import java.net.ServerSocket;
public class VeriAlma {
private static int port;
private static Socket socket;
public VeriAlma(int port)
{
VeriAlma.port=port;
}
public static void veriAl() {
try {
ServerSocket listener = new ServerSocket(port);
socket = listener.accept();
}
catch (java.lang.Exception ex) {
ex.printStackTrace(System.out);
}
}
public String run() {
try {
InputStream in = socket.getInputStream();
String file_name = "x.txt";
File file=new File(file_name);
ByteStream.toFile(in, file);
return file_name;
}
catch (java.lang.Exception ex) {
ex.printStackTrace(System.out);
return "asdasd";
}
}
public void setPort(int port)
{
VeriAlma.port=port;
}
}
Here is the client
package temel;
import java.io.*;
import java.net.*;
import java.lang.*;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.Socket;
public class VeriGonderme {
// host and port of receiver
private static int port;
private static String host;
public VeriGonderme(int port,String host)
{
this.port=port;
this.host=host;
}
public void veriGonder(String dosyaIsmi) {
try {
Socket socket = new Socket(host, port);
OutputStream os = socket.getOutputStream();
ByteStream.toStream(os, 1);
ByteStream.toStream(os, dosyaIsmi);
ByteStream.toStream(os, new File(dosyaIsmi));
}catch (Exception ex) {
ex.printStackTrace();
}
}
public void setPort(int port)
{
this.port=port;
}
public void setHost(String host)
{
this.host=host;
}
}
host is "localhost" port is 4444