Inputstream limitation?
hi. i have a server in java and a C# client. they are communicating through sockets. however when i tried to sent to send a image (a few mb)
the server would only received 7300 bytes.
some parts from my codes
int servPort= 3333;
ServerSocketservSock=new ServerSocket(servPort);
int i= 0;
byte[] byteBuffer =newbyte[BUFSIZE];
for (;;){// Run forever, accepting and servicing connections
SocketclntSock= servSock.accept();// Get client connection
System.out.println("Handling client at "+clntSock.getInetAddress().getHostAddress() +
" on port " + clntSock.getPort() );
InputStreamin= clntSock.getInputStream();
OutputStreamout= clntSock.getOutputStream();
OutputStreamout1=new FileOutputStream("outpic.jpg");
try{
System.out.print(" available: " + in.available() +"\n" );
i = in.read( byteBuffer );
any advice is appreciated.thanks in advance
# 1
let me guess (and it is only a guess since you don't have the rest of code here), your BUFSIZE is 7300, right?
The way this code looks currently, no matter what is sent, you read the first "BUFSIZE" bytes of it and ignore the rest. Can't say for sure since you cut the method of in the middle, but that is what it looks like.
# 3
sorry for not posting my full codes
public class TCPServer {
private static final int BUFSIZE = 1024*20;// Size of receive buffer
public static void main(String[] args) throws IOException {
intservPort= Integer.parseInt("4000");
// Create a server socket to accept client connection requests
ServerSocketservSock= new ServerSocket(servPort);
intrecvMsgSize;// Size of received message
byte[]byteBuffer= new byte[BUFSIZE];// Receive buffer
for (;;) { // Run forever, accepting and servicing connections
SocketclntSock= servSock.accept();// Get client connection
System.out.println("Handling client at " + clntSock.getInetAddress().getHostAddress() + " on port " + clntSock.getPort());
InputStreamin= clntSock.getInputStream();
OutputStreamout= clntSock.getOutputStream();
recvMsgSize = in.read(byteBuffer);
System.out.println( "recvMsgSize: " + recvMsgSize );
clntSock.close(); // Close the socket. We are done with this client!
}
}
}
# 6
Well, I guess I'll jump on the bandwagon again as well, and repeat, that as we have all said already, you need to loop (inside of your for loop, i.e. after you have accepted the connection) until you have received all the data. At the moment you are receiving, at max, BUFSIZE, which seems to be 20k.