在套接字的一侧,我知道数据正确地进入了套接字。
我建立了一个连接:
Connection sr = new Connection();
Server server = new Server("NAME", Interger.parseInt(port));
server.setIp(ip);
sr.setServer(server);
//I know my server connection code is correct because I can send and receive data in
//other areas of my program just fine
InputStream is = null;
try
{
is = sr.getChannel().socket().getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuffer text = new StringBuffer();
int k =0;
while(k != -1)
{
k = br.read();
text.append((char) k);
}
}
catch(Exception e)
{
//no errors ever get thrown
}
然后我只收到了大约一半的数据,即我发送的总共 21398 个字节中的 10989 个字节。它读取的字节数会有所不同,但数据总是以 ..., "values": ["
我发送的数据结尾,看起来像 , ..., "values": ["", ""]
。