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

[1494 byte] By [kenneth-rocka] at [2007-11-27 10:39:31]
# 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.

masijade.a at 2007-7-28 19:01:36 > top of Java-index,Core,Core APIs...
# 2

Also the read() method isn't guaranteed to return anything more than 1, or an exception. It's up to you to loop until you have all the data.

ejpa at 2007-7-28 19:01:36 > top of Java-index,Core,Core APIs...
# 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!

}

}

}

kenneth-rocka at 2007-7-28 19:01:36 > top of Java-index,Core,Core APIs...
# 4

You have this in a loop:

recvMsgSize = in.read(byteBuffer);

Don't you have to make a loop yourself to see how many bytes your getting and keep adding that onto the recvMsgSize +=

?

as epj said above

lokiea at 2007-7-28 19:01:36 > top of Java-index,Core,Core APIs...
# 5

Well your code is still exactly as I said in reply #2, i.e. wrong.

ejpa at 2007-7-28 19:01:36 > top of Java-index,Core,Core APIs...
# 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.

masijade.a at 2007-7-28 19:01:36 > top of Java-index,Core,Core APIs...