Java Client + SSL Socket Error when using two timers to connect to a server
<h2>Scenario</h2>

<p>ssl client that has two classes. One to transact and another to send network messages.
They share the connect function.
If i run each separately, the connection is made and appropriate response received.
If i run them concurrently, the connection is made but errors  like 
Errorjava.io.UTFDataFormatException: malformed input around byte 135
socket timeouts occur
the system eventually freezes.</p>

<h2>question</h2>

<p>how can i run the network and transact messages concurrently without them clashing as they are? </p>

<pre><code>// connect code
try {
            secureRandom = new SecureRandom();
            secureRandom.nextInt();
            System.out.println("Done.. Initializing Random Numbers.....:-");

            String host = getHost();
            int port = getPort();

            setupServerKeystore();
            setupClientKeyStore();
            setupSSLContext();

            SSLSocketFactory sf = sslContext.getSocketFactory();
            SSLSocket socket = (SSLSocket) sf.createSocket(host, port);
            socket.setSoTimeout(10000);
            InputStream in = socket.getInputStream();
            OutputStream out = socket.getOutputStream();

            this.din = new DataInputStream(in);
            this.dout = new DataOutputStream(out);

// snip

// Schedule the two timers to run with different delays.
        pingTimer.schedule(new Ping("ping"), 0, pingdelay);
        vendTimer.schedule(new Vend("vend"), 0, venddelay);
    } // end main
</code></pre>

<p>// stacktrace</p>

<pre><code>vend - Current time: 20.04.2012 12:04:28

ping - Current time: 20.04.2012 12:04:28
Incoming Errorjava.io.UTFDataFormatException: malformed input around byte 135
java.io.UTFDataFormatException: malformed input around byte 135
    at java.io.DataInputStream.readUTF(DataInputStream.java:639)
    at java.io.DataInputStream.readUTF(DataInputStream.java:547)
    at timerexample.Ping.run(Ping.java:76)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
=========== Connected is True
null
ping - Current time: 20.04.2012 12:04:30
Incoming Errorjava.net.SocketTimeoutException: Read timed out
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
=========== Connected is True
null
vend - Current time: 20.04.2012 12:04:46
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:746)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
    at java.io.DataInputStream.readFully(DataInputStream.java:178)
    at java.io.DataInputStream.readUTF(DataInputStream.java:592)
    at java.io.DataInputStream.readUTF(DataInputStream.java:547)
    at timerexample.Ping.run(Ping.java:76)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
Incoming Errorjava.net.SocketTimeoutException: Read timed out
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:746)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
    at java.io.DataInputStream.readFully(DataInputStream.java:178)
    at java.io.DataInputStream.readUTF(DataInputStream.java:592)
    at java.io.DataInputStream.readUTF(DataInputStream.java:547)
    at timerexample.Ping.run(Ping.java:76)
=========== Connected is True
null
ping - Current time: 20.04.2012 12:05:02
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
java.net.SocketTimeoutException: Read timed out
Incoming Errorjava.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:746)
=========== Connected is True
null
ping - Current time: 20.04.2012 12:05:17
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:50)
    at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:320)
    at java.io.DataInputStream.readUTF(DataInputStream.java:572)
    at java.io.DataInputStream.readUTF(DataInputStream.java:547)
    at timerexample.Ping.run(Ping.java:76)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
</code></pre>
