1. Michael Caron
  2. IntelixNetLib

Commits

Michael Caron  committed 8ed27c6

Increased buffer to 1k (granted, larger than necessary, but it's still going to work).
Clears input buffer before each write to make sure there's nothing unexpected on the wire.

  • Participants
  • Parent commits b45a0ac
  • Branches default

Comments (0)

Files changed (2)

File src/main/java/com/intelix/net/Connection.java

View file
 
 public abstract class Connection {
 
-    static final int MAX_BUFFER_SIZE = 70;
+    static final int MAX_BUFFER_SIZE = 1024 /* increased from 70 */;
     private byte[] bufferIn;
     private byte[] bufferOut;
     private int buffLimit = 0;
             }
             Logger.getLogger(getClass().getName()).log(Level.FINE, ">>>>WRITE: [{0}]", sBuff);
 
+            clearInput(500);
             getOutStream().write(bufferOut);
             getOutStream().flush();
 
     }
 
     public void write(List<Command> commands) throws IOException {
+        /* maybe try writing all the commands at once to improve perf. */
         for (Command c : commands) {
             write(c);
         }
             {
                 int avl = in.available();
                 Logger.getLogger(getClass().getName()).log(Level.FINE,"Clearing input buffer. Bytes available: {0}.",avl);
-                in.skip(in.available());
+                long skipped = in.skip(avl);
+                Logger.getLogger(getClass().getName()).log(Level.FINE, "Skipped {0} bytes", skipped);
                 try {
                     Logger.getLogger(getClass().getName()).log(Level.FINE,"Waiting {0} before another clearing.",waitTimeInMillisec);
                     Thread.sleep(waitTimeInMillisec);

File src/main/java/com/intelix/net/IPConnection.java

View file
         if (!this.connected) {
             return;
         }
-        this.outStream = new BufferedOutputStream(this.sock.getOutputStream());
-        this.inStream = new BufferedInputStream(this.sock.getInputStream());
+        this.outStream = new BufferedOutputStream(this.sock.getOutputStream(), MAX_BUFFER_SIZE);
+        this.inStream = new BufferedInputStream(this.sock.getInputStream(), MAX_BUFFER_SIZE);
     }
 
     @Override