I'm coding a client-server service where my server is sending files to the client.
In the following example, I tried to send a list of file names to my client.
Server
serverSocket = new ServerSocket(4000);
connsock = serverSocket.accept();
objectOutput = new ObjectOutputStream(connsock.getOutputStream());
List<String> file_names = new ArrayList<String>();
File[] files = new File("C:\ServerMusicStorage").listFiles();
for (File file : files) {
if (file.isFile()) {
file_names.add(file.getName());
}
}
objectOutput.writeObject(file_names);
objectOutput.flush();
Client
newclientSocket = new Socket("localhost", 4000);
objectInput1 = new ObjectInputStream(newclientSocket.getInputStream());
System.out.println("<---Available files--->");
// get list of files from server
Object file_names = objectInput1.readObject();
file_list = (ArrayList<String>) file_names;
int count = 1;
for (int i = 0; i < file_list.size(); i++) {
System.out.println(count + ")" + file_list.get(i));
count++;
}
So when I run my program at java NetBeans IDE it works as I want. I get the files
<---Available files--->
1)blank.wav
2)fuark.wav
For the docker connection i created a network with
docker network create client_server_network
I run the server with
docker run --env SERVER_HOST_ENV=server --network-alias server --network client_server_network -it server
and the client with
docker run --network client_server_network -it clientimage
Although the client-server connection is successful through docker containers, when I run both services I don't get any output.
<---Available files--->
I'm stuck in this for days. What might be wrong? If I should provide any other information please tell me.
P.S. at the server-side of docker I set the server image as the host newclientSocket = new Socket("server", 4000)
question from:
https://stackoverflow.com/questions/65651926/docker-with-java-sockets-data-streams-not-recognized 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…