Length of readline argument is intenger.
I have to specify the number of characters to read.
For example, if these two files are randomly sent from java,I try to send from java to prolog.
In case only client_send.txt, read_string(In,35,String) is perfect,
But in case sending client_send2.txt, read_string(In,35,String) is not perfect.
It’s reading only half of client_send2.txt.
I want to be able to read all the characters even if the character streams from both files are sent.
Also, even if the file (client_send.txt or client_send2.txt) is sent multiple times in succession,
I want to be able to read everything using Repeat etc.
In other words, I want to read all characters even if the file is sent many times from java after connecting once with tcp.
Read at most Length characters from Stream and return them in the string String. If Length is unbound, Stream is read to the end and Length is unified with the number of characters read.
So, if you do read_string(Stream, StringLength, String) you’ll read everything into String and StringLength will unify with the length of that string (assuming StringLength is unbound; otherwise see the next paragraph). You can also do read_string(Stream, _, String) to get the same result (if you want the length, use string_length/2).
If you do read_string(Stream, 1000, String), then at most 1000 characters will be read into String. You can also do MaxRead=1000, read_string(Stream, MaxRead, String), to get the same result.
Because read_line/3 is waiting for the end-of-stream, which it sees only if the client is closed. If you want to see input before end-of-stream, then specify a length, but you have to deal with figuring out how much you want to read – you can do character at a time, if you wish. Or, try read_string/5.
You might want to try using nc -vv localhost 2011 instead of your Java client (might need options -N and -q 1)
For testing, utilities such as netcat (ncat, nc) are very useful, because they’ve been used for years and have had their bugs and idiosyncrasies worked out. You can also look at their source code; the code is fairly simple once you get past all the options. (I would also recommend doing your first development on a Linux or Unix system; Windows adds some additional complications.) If you really can’t figure out what’s going on, use Wireshark or tcpdump to look at the packets and flows – it’s quite easy to use and is very instructive.