I have a purpose for creating a client-server file transfer application. This may be a simple example. I tried the examples asked in similar questions in SOF, but they could not transfer the file.
I am trying to pass client and server through sockets. If there could be someone who could help me, I will be glad.
The client will upload the file to the server. Also, the client can download the file from the server. This is how to create an application.
Here is the client side code:
package wdc; import java.io.*; import java.io.ByteArrayOutputStream; import java.net.*; class TCPClient { public static void main(String args[]) { byte[] aByte = new byte[1]; int bytesRead; Socket clientSocket = null; InputStream is = null; try { clientSocket = new Socket("127.0.0.1", 3248); is = clientSocket.getInputStream(); } catch (IOException ex) {
Here is the server side code:
package wds; import java.io.*; import java.net.*; class TCPServer { public static void main(String args[]) { while (true) { ServerSocket welcomeSocket = null; Socket connectionSocket = null; BufferedOutputStream outToClient = null; try { welcomeSocket = new ServerSocket(3248); connectionSocket = welcomeSocket.accept(); outToClient = new BufferedOutputStream(connectionSocket.getOutputStream()); } catch (IOException ex) {
I could not run these source files, and I do not know why.
source share