View Single Post
  #3   Spotlight this post!  
Unread 10-03-2012, 19:24
ProgrammerMatt ProgrammerMatt is offline
Programmer-Electrical-Mechanical
FRC #0228 (Gus)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Southington
Posts: 138
ProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really nice
Re: URGENT Sending data over tcp

Quote:
Originally Posted by derekwhite View Post
Here are some things to check out:

1) Is RoboRealm flushing output at every int, or is getting buffered?

2) Why is "instream.read()" called 2x in your loop?

3) The field "Socket.datain" is being used to communicate between threads. For correct portable code this should be declared "volatile", or all reads and writes should be guarded by synchronized statements. This shouldn't actually matter for Java on the cRIO though.

4) There isn't any built-in Java-level input buffering on a Socket's input stream in this version of Java. That shouldn't result in a 10x slowdown though.

To test this you could try reading into a 4-byte array, and constructing an int from that

Code:
byte b[] = new byte[4];

while (true) {
    int len = instream.read(b, 0, b.length); // should check that len is 4, and buffer up until full, but in practice you should see 4 bytes...

    datain = (b[0] << 24) | ((b[1] & 0xFF) << 16) |((b[2] & 0xFF) << 8) | (b[1] & 0xFF);  // or reverse the byte order if necessary.
}
I will try this thanks, also is UDP a better choice for speed?
Sorry but i dont understand what int len is for?

P.S, Yea i just noticed that there is 2 instream.read();

Last edited by ProgrammerMatt : 10-03-2012 at 19:31.
Reply With Quote