Skip to content

Instantly share code, notes, and snippets.

@yasincidem
Created May 2, 2019 11:11
Show Gist options
  • Save yasincidem/6e6bf129f40ce0fcaa38ee928687d94e to your computer and use it in GitHub Desktop.
Save yasincidem/6e6bf129f40ce0fcaa38ee928687d94e to your computer and use it in GitHub Desktop.
Client.java
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
/**
* Created by yasin_000 on 1.5.2019.
*/
public class Client {
public final static String FILE_TO_SEND = "C:\\Users\\yasin_000\\Desktop\\NetworkHW\\image.jpg"; // you may change this
public static void main(String[] args) throws IOException {
final Socket socket = createSocket("localhost", 4999);
File file = new File(FILE_TO_SEND);
final byte[] bytes = Utils.fileToBytes(file);
OutputStream is = socket.getOutputStream();
is.write(bytes, 0, bytes.length);
}
private static Socket createSocket(String addr, int port) {
Socket socket = null;
try {
socket = new Socket(addr, port);
} catch (IOException e) {
e.printStackTrace();
System.err.println(e.getMessage());
}
return socket;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment