java服务器端接受的最后一个包始终要查几十个字节,不知道怎么回事?vc:
BYTE d[1024];
int iWrote=0;
while(!feof(fp))
{
int num=fread((void*)d,1,1024,fp);
printf("have read file %d byte\n",num);
iWrote=send(connectSock,(const char* )d,num,MSG_OOB); printf("have send %d byte\n",iWrote);
}
java:
DataInputStream r=new DataInputStream(socket.getInputStream());
byte[] data=new byte[1024];
File f2=new File("1.bmp");
FileOutputStream out=new FileOutputStream(f2);
int length=0;int a=0;
while((a=r.read(data))!=-1)
{
try{
out.write(data,0,a);
}
catch(Exception e)
{
e.printStackTrace();
}
}
BYTE d[1024];
int iWrote=0;
while(!feof(fp))
{
int num=fread((void*)d,1,1024,fp);
printf("have read file %d byte\n",num);
iWrote=send(connectSock,(const char* )d,num,MSG_OOB); printf("have send %d byte\n",iWrote);
}
java:
DataInputStream r=new DataInputStream(socket.getInputStream());
byte[] data=new byte[1024];
File f2=new File("1.bmp");
FileOutputStream out=new FileOutputStream(f2);
int length=0;int a=0;
while((a=r.read(data))!=-1)
{
try{
out.write(data,0,a);
}
catch(Exception e)
{
e.printStackTrace();
}
}
BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
int buffer_size = 1024, n;
char[] data = new char[buffer_size];
while((n = reader.read(data)) != -1){
//data
}
reader.close();
……
vc:
connect to a socket
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 1024 byte
have send 974 byte
java:
have recv 1023 total 1023
have recv 1023 total 2046
have recv 1023 total 3069
have recv 1023 total 4092
have recv 1023 total 5115
have recv 1023 total 6138
have recv 1023 total 7161
have recv 1023 total 8184
have recv 1023 total 9207
have recv 1023 total 10230
have recv 1023 total 11253
have recv 1023 total 12276
have recv 1023 total 13299
have recv 1023 total 14322
have recv 1023 total 15345
have recv 1023 total 16368
have recv 1023 total 17391
have recv 1023 total 18414
have recv 1023 total 19437
have recv 1023 total 20460
have recv 1023 total 21483
have recv 1023 total 22506
have recv 1023 total 23529
have recv 1023 total 24552
have recv 1023 total 25575
have recv 1023 total 26598
have recv 1023 total 27621
have recv 1023 total 28644
have recv 1023 total 29667
have recv 1023 total 30690
have recv 1023 total 31713
have recv 1023 total 32736
have recv 1023 total 33759
have recv 1023 total 34782
have recv 1023 total 35805
have recv 1023 total 36828
have recv 1023 total 37851
have recv 973 total 38824怎么每次都差一个字节???