I study Spark streams for real-time data processing, and I built a wordCount example of a spark stream, and I can run the example after: / bin / run -example org.apache.spark.streaming.examples.JavaNetworkWordCount local [2] localhost 9999
And I run "nc -L -p 9999" in another terminal, then I can type letters in this terminal, and the example can get the letters and give the correct result.
But I developed a java socket client to send content to port 9999, why can't it get it? I think the example just controls port 9999 and gets something from the port.
following java parts:
File file = new File("D:\\OutputJson.dat");
long l = file.length();
socket = new Socket();
boolean connected = false;
while (!connected) {
try {
socket.connect(new InetSocketAddress("localhost", 9999));
connected = true;
System.out.println("connected success!");
} catch (Exception e) {
e.printStackTrace();
System.out.println("connected failed!");
Thread.sleep(5000);
}
}
dos = new DataOutputStream(socket.getOutputStream());
fis = new FileInputStream(file);
sendBytes = new byte[1024];
while ((length = fis.read(sendBytes, 0, sendBytes.length)) > 0) {
sumL += length;
System.out.println("sent:" + ((sumL / l) * 100) + "%");
dos.write(sendBytes, 0, length);
dos.flush();
}
if (sumL == l) {
bool = true;
}
this java function always returns an error: java.net.SocketException: socket is closed
java , , ?