diff --git a/Extasys for Java Examples/Extasys.Examples.TCPClient/build/built-jar.properties b/Extasys for Java Examples/Extasys.Examples.TCPClient/build/built-jar.properties index cb5a091..a6981d3 100644 --- a/Extasys for Java Examples/Extasys.Examples.TCPClient/build/built-jar.properties +++ b/Extasys for Java Examples/Extasys.Examples.TCPClient/build/built-jar.properties @@ -1,4 +1,4 @@ -#Sun, 24 Nov 2013 18:12:25 +0200 +#Sun, 19 Jan 2014 18:17:42 +0200 D\:\\Development\\Source\ Rabbit\\Extasys\\Extasys\ for\ Java\ Examples\\Extasys.Examples.TCPClient= diff --git a/Extasys for Java Examples/Extasys.Examples.TCPClient/build/classes/Extasys/Examples/TCPClient/AutoSendMessages.class b/Extasys for Java Examples/Extasys.Examples.TCPClient/build/classes/Extasys/Examples/TCPClient/AutoSendMessages.class index cb26697..b7a1479 100644 Binary files a/Extasys for Java Examples/Extasys.Examples.TCPClient/build/classes/Extasys/Examples/TCPClient/AutoSendMessages.class and b/Extasys for Java Examples/Extasys.Examples.TCPClient/build/classes/Extasys/Examples/TCPClient/AutoSendMessages.class differ diff --git a/Extasys for Java Examples/Extasys.Examples.TCPClient/build/classes/Extasys/Examples/TCPClient/TCPClient.class b/Extasys for Java Examples/Extasys.Examples.TCPClient/build/classes/Extasys/Examples/TCPClient/TCPClient.class index bc33355..dede64a 100644 Binary files a/Extasys for Java Examples/Extasys.Examples.TCPClient/build/classes/Extasys/Examples/TCPClient/TCPClient.class and b/Extasys for Java Examples/Extasys.Examples.TCPClient/build/classes/Extasys/Examples/TCPClient/TCPClient.class differ diff --git a/Extasys for Java Examples/Extasys.Examples.TCPClient/dist/lib/Extasys.jar b/Extasys for Java Examples/Extasys.Examples.TCPClient/dist/lib/Extasys.jar index 3877dc8..ad2d1c0 100644 Binary files a/Extasys for Java Examples/Extasys.Examples.TCPClient/dist/lib/Extasys.jar and b/Extasys for Java Examples/Extasys.Examples.TCPClient/dist/lib/Extasys.jar differ diff --git a/Extasys for Java Examples/Extasys.Examples.TCPClient/src/Extasys/Examples/TCPClient/TCPClient.java b/Extasys for Java Examples/Extasys.Examples.TCPClient/src/Extasys/Examples/TCPClient/TCPClient.java index c3c9295..e787f7f 100644 --- a/Extasys for Java Examples/Extasys.Examples.TCPClient/src/Extasys/Examples/TCPClient/TCPClient.java +++ b/Extasys for Java Examples/Extasys.Examples.TCPClient/src/Extasys/Examples/TCPClient/TCPClient.java @@ -24,6 +24,9 @@ of this software and associated documentation files (the "Software"), to deal import Extasys.Network.TCP.Client.Exceptions.ConnectorCannotSendPacketException; import Extasys.Network.TCP.Client.Exceptions.ConnectorDisconnectedException; import java.net.InetAddress; +import java.nio.charset.Charset; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -33,6 +36,7 @@ public class TCPClient extends Extasys.Network.TCP.Client.ExtasysTCPClient { private AutoSendMessages fAutoSendMessagesThread; + private Charset fCharset = Charset.forName("UTF-8"); public TCPClient(String name, String description, InetAddress remoteHostIP, int remoteHostPort, int corePoolSize, int maximumPoolSize) { @@ -49,7 +53,16 @@ public TCPClient(String name, String description, InetAddress remoteHostIP, int @Override public void OnDataReceive(TCPConnector connector, DataFrame data) { - //System.out.println("Data received: " + new String(data.getBytes())); + try + { + String dataStr = new String(data.getBytes(), fCharset); + + connector.SendData(dataStr + "#SPLITTER#"); + } + catch (Exception ex) + { + + } } @Override @@ -68,8 +81,21 @@ public void OnDisconnect(TCPConnector connector) public void StartSendingMessages() { StopSendingMessages(); - fAutoSendMessagesThread = new AutoSendMessages(this); - fAutoSendMessagesThread.start(); + try + { + SendData("1#SPLITTER#"); + +//fAutoSendMessagesThread = new AutoSendMessages(this); + //fAutoSendMessagesThread.start(); + } + catch (ConnectorDisconnectedException ex) + { + Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex); + } + catch (ConnectorCannotSendPacketException ex) + { + Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex); + } } public void StopSendingMessages() diff --git a/Extasys for Java Examples/Extasys.Examples.TCPServer/build/built-clean.properties b/Extasys for Java Examples/Extasys.Examples.TCPServer/build/built-clean.properties new file mode 100644 index 0000000..b2151c0 --- /dev/null +++ b/Extasys for Java Examples/Extasys.Examples.TCPServer/build/built-clean.properties @@ -0,0 +1,6 @@ +#Sun, 19 Jan 2014 16:20:13 +0200 + + +D\:\\Development\\Source\ Rabbit\\Extasys\\Extasys\ for\ Java\ Examples\\Extasys.Examples.TCPServer= + +D\:\\Development\\Source\ Rabbit\\Extasys\\Extasys\ for\ Java= diff --git a/Extasys for Java Examples/Extasys.Examples.TCPServer/build/built-jar.properties b/Extasys for Java Examples/Extasys.Examples.TCPServer/build/built-jar.properties index 904297d..d578157 100644 --- a/Extasys for Java Examples/Extasys.Examples.TCPServer/build/built-jar.properties +++ b/Extasys for Java Examples/Extasys.Examples.TCPServer/build/built-jar.properties @@ -1,4 +1,4 @@ -#Sun, 24 Nov 2013 18:12:22 +0200 +#Sun, 19 Jan 2014 18:17:12 +0200 D\:\\Development\\Source\ Rabbit\\Extasys\\Extasys\ for\ Java\ Examples\\Extasys.Examples.TCPServer= diff --git a/Extasys for Java Examples/Extasys.Examples.TCPServer/build/classes/Extasys/Examples/TCPServer/TCPServer.class b/Extasys for Java Examples/Extasys.Examples.TCPServer/build/classes/Extasys/Examples/TCPServer/TCPServer.class index a89998a..db081cc 100644 Binary files a/Extasys for Java Examples/Extasys.Examples.TCPServer/build/classes/Extasys/Examples/TCPServer/TCPServer.class and b/Extasys for Java Examples/Extasys.Examples.TCPServer/build/classes/Extasys/Examples/TCPServer/TCPServer.class differ diff --git a/Extasys for Java Examples/Extasys.Examples.TCPServer/dist/lib/Extasys.jar b/Extasys for Java Examples/Extasys.Examples.TCPServer/dist/lib/Extasys.jar index e3523ef..899dbe3 100644 Binary files a/Extasys for Java Examples/Extasys.Examples.TCPServer/dist/lib/Extasys.jar and b/Extasys for Java Examples/Extasys.Examples.TCPServer/dist/lib/Extasys.jar differ diff --git a/Extasys for Java Examples/Extasys.Examples.TCPServer/src/Extasys/Examples/TCPServer/TCPServer.java b/Extasys for Java Examples/Extasys.Examples.TCPServer/src/Extasys/Examples/TCPServer/TCPServer.java index e90ee4d..ca6f291 100644 --- a/Extasys for Java Examples/Extasys.Examples.TCPServer/src/Extasys/Examples/TCPServer/TCPServer.java +++ b/Extasys for Java Examples/Extasys.Examples.TCPServer/src/Extasys/Examples/TCPServer/TCPServer.java @@ -23,6 +23,7 @@ of this software and associated documentation files (the "Software"), to deal import Extasys.Network.TCP.Server.Listener.TCPClientConnection; import Extasys.Network.TCP.Server.Listener.TCPListener; import java.net.InetAddress; +import java.nio.charset.Charset; /** * @@ -32,6 +33,7 @@ public class TCPServer extends Extasys.Network.TCP.Server.ExtasysTCPServer { private TCPListener fMyTCPListener; + private Charset fCharset = Charset.forName("UTF-8"); public TCPServer(String name, String description, InetAddress listenerIP, int port, int maxConnections, int connectionsTimeOut, int corePoolSize, int maximumPoolSize) { @@ -52,7 +54,9 @@ public void OnDataReceive(TCPClientConnection sender, DataFrame data) { try { - sender.SendData("GET#SPLITTER#"); + byte[] bytes = data.getBytes(); + + sender.SendDataSynchronous(new String(bytes, fCharset) + "#SPLITTER#"); } catch (Exception ex) { diff --git a/Extasys for Java/build/built-jar.properties b/Extasys for Java/build/built-jar.properties new file mode 100644 index 0000000..6d6f626 --- /dev/null +++ b/Extasys for Java/build/built-jar.properties @@ -0,0 +1,4 @@ +#Sun, 19 Jan 2014 17:04:29 +0200 + + +D\:\\Development\\Source\ Rabbit\\Extasys\\Extasys\ for\ Java= diff --git a/Extasys for Java/build/classes/.netbeans_automatic_build b/Extasys for Java/build/classes/.netbeans_automatic_build deleted file mode 100644 index e69de29..0000000 diff --git a/Extasys for Java/build/classes/.netbeans_update_resources b/Extasys for Java/build/classes/.netbeans_update_resources deleted file mode 100644 index e69de29..0000000 diff --git a/Extasys for Java/build/classes/Extasys/ManualResetEvent.class b/Extasys for Java/build/classes/Extasys/ManualResetEvent.class index 727f801..73b81bd 100644 Binary files a/Extasys for Java/build/classes/Extasys/ManualResetEvent.class and b/Extasys for Java/build/classes/Extasys/ManualResetEvent.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/IncomingTCPClientPacket.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/IncomingTCPClientPacket.class index db29ab5..b3b38eb 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/IncomingTCPClientPacket.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/IncomingTCPClientPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/MessageCollectorTCPClientPacket.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/MessageCollectorTCPClientPacket.class index 8ae1379..4e16182 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/MessageCollectorTCPClientPacket.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/MessageCollectorTCPClientPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/OutgoingTCPClientPacket.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/OutgoingTCPClientPacket.class index 16f8189..4824908 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/OutgoingTCPClientPacket.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/Packets/OutgoingTCPClientPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/ReadIncomingDataThread.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/ReadIncomingDataThread.class index 13e2630..a156eb6 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/ReadIncomingDataThread.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/ReadIncomingDataThread.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/TCPConnector.rs b/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/TCPConnector.rs deleted file mode 100644 index feef740..0000000 --- a/Extasys for Java/build/classes/Extasys/Network/TCP/Client/Connectors/TCPConnector.rs +++ /dev/null @@ -1,2 +0,0 @@ -Extasys.Network.TCP.Client.Connectors.TCPConnector -Extasys.Network.TCP.Client.Connectors.ReadIncomingDataThread diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/ClientDataReader.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/ClientDataReader.class index 1ff3731..707352e 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/ClientDataReader.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/ClientDataReader.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/IncomingTCPClientConnectionPacket.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/IncomingTCPClientConnectionPacket.class index f10db00..0ff2767 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/IncomingTCPClientConnectionPacket.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/IncomingTCPClientConnectionPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/MessageCollectorTCPClientConnectionPacket.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/MessageCollectorTCPClientConnectionPacket.class index 6daa7c5..b2b97b5 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/MessageCollectorTCPClientConnectionPacket.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/MessageCollectorTCPClientConnectionPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/OutgoingTCPClientConnectionPacket.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/OutgoingTCPClientConnectionPacket.class index d86054c..9fbaef0 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/OutgoingTCPClientConnectionPacket.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/Packets/OutgoingTCPClientConnectionPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPClientConnection.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPClientConnection.class index a078283..20f5a48 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPClientConnection.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPClientConnection.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPClientConnection.rs b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPClientConnection.rs deleted file mode 100644 index 9c96634..0000000 --- a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPClientConnection.rs +++ /dev/null @@ -1,2 +0,0 @@ -Extasys.Network.TCP.Server.Listener.TCPClientConnection -Extasys.Network.TCP.Server.Listener.ClientDataReader diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPListener.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPListener.class index fa88d4b..3e362e5 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPListener.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPListener.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPListenerThread.class b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPListenerThread.class index 265f6e9..f14fafe 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPListenerThread.class and b/Extasys for Java/build/classes/Extasys/Network/TCP/Server/Listener/TCPListenerThread.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/Packets/IncomingUDPClientPacket.class b/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/Packets/IncomingUDPClientPacket.class index b7548e9..ec3a4e4 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/Packets/IncomingUDPClientPacket.class and b/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/Packets/IncomingUDPClientPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/Packets/OutgoingUDPClientPacket.class b/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/Packets/OutgoingUDPClientPacket.class index 176d1b1..a9bfaa2 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/Packets/OutgoingUDPClientPacket.class and b/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/Packets/OutgoingUDPClientPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/ReadIncomingData.class b/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/ReadIncomingData.class index 447ca71..1adb167 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/ReadIncomingData.class and b/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/ReadIncomingData.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/UDPConnector.rs b/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/UDPConnector.rs deleted file mode 100644 index e6dbc3c..0000000 --- a/Extasys for Java/build/classes/Extasys/Network/UDP/Client/Connectors/UDPConnector.rs +++ /dev/null @@ -1,2 +0,0 @@ -Extasys.Network.UDP.Client.Connectors.UDPConnector -Extasys.Network.UDP.Client.Connectors.ReadIncomingData diff --git a/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/Packets/IncomingUDPServerPacket.class b/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/Packets/IncomingUDPServerPacket.class index 20403e8..5df8794 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/Packets/IncomingUDPServerPacket.class and b/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/Packets/IncomingUDPServerPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/Packets/OutgoingUDPServerPacket.class b/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/Packets/OutgoingUDPServerPacket.class index 4b4d8bc..27db144 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/Packets/OutgoingUDPServerPacket.class and b/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/Packets/OutgoingUDPServerPacket.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/ReadIncomingDataThread.class b/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/ReadIncomingDataThread.class index 2622e77..91faddd 100644 Binary files a/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/ReadIncomingDataThread.class and b/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/ReadIncomingDataThread.class differ diff --git a/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/UDPListener.rs b/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/UDPListener.rs deleted file mode 100644 index b7fc8ff..0000000 --- a/Extasys for Java/build/classes/Extasys/Network/UDP/Server/Listener/UDPListener.rs +++ /dev/null @@ -1,2 +0,0 @@ -Extasys.Network.UDP.Server.Listener.UDPListener -Extasys.Network.UDP.Server.Listener.ReadIncomingDataThread diff --git a/Extasys for Java/dist/Extasys.jar b/Extasys for Java/dist/Extasys.jar index 1ad0ea0..228ac1b 100644 Binary files a/Extasys for Java/dist/Extasys.jar and b/Extasys for Java/dist/Extasys.jar differ diff --git a/Extasys for Java/nbproject/private/private.xml b/Extasys for Java/nbproject/private/private.xml index cd3e03d..b6a1931 100644 --- a/Extasys for Java/nbproject/private/private.xml +++ b/Extasys for Java/nbproject/private/private.xml @@ -3,6 +3,10 @@ - + + file:/D:/Development/Source%20Rabbit/Extasys/Extasys%20for%20Java/src/Extasys/Network/TCP/Client/Connectors/TCPConnector.java + file:/D:/Development/Source%20Rabbit/Extasys/Extasys%20for%20Java/src/Extasys/Network/TCP/Server/Listener/Packets/OutgoingTCPClientConnectionPacket.java + file:/D:/Development/Source%20Rabbit/Extasys/Extasys%20for%20Java/src/Extasys/Network/TCP/Server/Listener/TCPClientConnection.java + diff --git a/Extasys for Java/src/Extasys/ManualResetEvent.java b/Extasys for Java/src/Extasys/ManualResetEvent.java index d16668e..c341cd0 100644 --- a/Extasys for Java/src/Extasys/ManualResetEvent.java +++ b/Extasys for Java/src/Extasys/ManualResetEvent.java @@ -69,6 +69,6 @@ public synchronized void WaitOne(long milliseconds) public synchronized void Set() { fInitialState = true; - notify(); + notifyAll(); } } diff --git a/Extasys for Java/src/Extasys/Network/TCP/Client/Connectors/TCPConnector.java b/Extasys for Java/src/Extasys/Network/TCP/Client/Connectors/TCPConnector.java index d5ee7cb..49b3a17 100644 --- a/Extasys for Java/src/Extasys/Network/TCP/Client/Connectors/TCPConnector.java +++ b/Extasys for Java/src/Extasys/Network/TCP/Client/Connectors/TCPConnector.java @@ -290,6 +290,41 @@ public void SendData(byte[] bytes, int offset, int length) throws ConnectorDisco } } + /** + * Send data to server and wait until data transfer complete. + * + * @param data is the string data to send + * @throws ConnectorDisconnectedException + */ + public void SendDataSynchronous(String data) throws ConnectorDisconnectedException + { + byte[] bytes = data.getBytes(); + SendDataSynchronous(bytes, 0, bytes.length); + } + + /** + * Send data to server and wait until data transfer complete. + * + * @param bytes is the byte array to be send. + * @param offset is the position in the data buffer at witch to begin + * sending. + * @param length is the number of the bytes to be send. + * @throws ConnectorDisconnectedException + */ + public void SendDataSynchronous(byte[] bytes, int offset, int length) throws ConnectorDisconnectedException + { + try + { + fOutput.write(bytes, offset, length); + fBytesOut += length; + } + catch (IOException ex) + { + Stop(); + throw new ConnectorDisconnectedException(this); + } + } + /** * Returns the main Extasys TCP Client of the connector. * diff --git a/Extasys for Java/src/Extasys/Network/TCP/Server/Listener/Packets/OutgoingTCPClientConnectionPacket.java b/Extasys for Java/src/Extasys/Network/TCP/Server/Listener/Packets/OutgoingTCPClientConnectionPacket.java index 5b66abd..5312880 100644 --- a/Extasys for Java/src/Extasys/Network/TCP/Server/Listener/Packets/OutgoingTCPClientConnectionPacket.java +++ b/Extasys for Java/src/Extasys/Network/TCP/Server/Listener/Packets/OutgoingTCPClientConnectionPacket.java @@ -95,6 +95,7 @@ public void run() { fClient.fOutput.write(fBytes, fOffset, fLength); fClient.fBytesOut += fLength; + fClient.fMyListener.fBytesOut += fLength; } catch (IOException ioException) { @@ -111,6 +112,8 @@ public void run() try { fClient.fOutput.write(fBytes, fOffset, fLength); + fClient.fBytesOut += fLength; + fClient.fMyListener.fBytesOut += fLength; } catch (IOException ioException) { diff --git a/Extasys for Java/src/Extasys/Network/TCP/Server/Listener/TCPClientConnection.java b/Extasys for Java/src/Extasys/Network/TCP/Server/Listener/TCPClientConnection.java index a88eab2..38d73ca 100644 --- a/Extasys for Java/src/Extasys/Network/TCP/Server/Listener/TCPClientConnection.java +++ b/Extasys for Java/src/Extasys/Network/TCP/Server/Listener/TCPClientConnection.java @@ -41,20 +41,20 @@ of this software and associated documentation files (the "Software"), to deal * * @author Nikos Siatras */ -public class TCPClientConnection +public final class TCPClientConnection { //Connection properties - public Socket fConnection; + protected Socket fConnection; protected boolean fActive = false; protected boolean fIsConnected = false; - private TCPListener fMyListener; + public TCPListener fMyListener; public ExtasysTCPServer fMyExtasysServer; private String fIPAddress; private String fName = ""; private Object fTag = null; private Thread fClientDataReaderThread; - private Date fConnectionStartUpDateTime; + private final Date fConnectionStartUpDateTime; //Data input-output streams. public InputStream fInput; public OutputStream fOutput; @@ -62,7 +62,7 @@ public class TCPClientConnection public long fBytesIn = 0, fBytesOut = 0; //Message collector. public TCPClientConnectionMessageCollector fMyMessageCollector; - protected boolean fUseMessageCollector; + protected final boolean fUseMessageCollector; //Messages IO. public IncomingTCPClientConnectionPacket fLastIncomingPacket = null; public OutgoingTCPClientConnectionPacket fLastOugoingPacket = null; @@ -70,11 +70,13 @@ public class TCPClientConnection public TCPClientConnection(Socket socket, TCPListener myTCPListener, boolean useMessageCollector, String ETX) { + fConnectionStartUpDateTime = ExtasysCalendar.fCalendar.getTime(); + fUseMessageCollector = useMessageCollector; + fConnection = socket; + try { - fUseMessageCollector = useMessageCollector; fIPAddress = socket.getInetAddress().toString() + ":" + String.valueOf(socket.getPort()); - fConnection = socket; fIsConnected = true; if (myTCPListener.getConnectionTimeOut() > 0) //Connection time-out. @@ -105,8 +107,6 @@ public TCPClientConnection(Socket socket, TCPListener myTCPListener, boolean use fMyListener.AddClient(this); StartReceivingData(); - - fConnectionStartUpDateTime = ExtasysCalendar.fCalendar.getTime(); } private void StartReceivingData() @@ -162,11 +162,54 @@ public void SendData(byte[] bytes, int offset, int length) throws ClientIsDiscon { throw new ClientIsDisconnectedException(this); } - fBytesOut += length; - fMyListener.fBytesOut += length; fLastOugoingPacket = new OutgoingTCPClientConnectionPacket(this, bytes, offset, length, fLastOugoingPacket); } + /** + * Send data to client and wait until data transfer complete. + * + * @param data is the string to send. + * @throws ClientIsDisconnectedException + */ + public void SendDataSynchronous(String data) throws ClientIsDisconnectedException + { + byte[] bytes = data.getBytes(); + SendDataSynchronous(bytes, 0, bytes.length); + } + + /** + * Send data to client and wait until data transfer complete. + * + * @param bytes is the byte array to be send. + * @param offset is the position in the data buffer at witch to begin + * @param length is the number of the bytes to be send. + * @throws + * Extasys.Network.TCP.Server.Listener.Exceptions.ClientIsDisconnectedException + */ + public void SendDataSynchronous(byte[] bytes, int offset, int length) throws ClientIsDisconnectedException + { + if (!this.fIsConnected) + { + throw new ClientIsDisconnectedException(this); + } + + try + { + fOutput.write(bytes, offset, length); + fBytesOut += length; + fMyListener.fBytesOut += length; + } + catch (IOException ex) + { + if (fLastOugoingPacket != null) + { + fLastOugoingPacket.Cancel(); + } + this.DisconnectMe(); + throw new ClientIsDisconnectedException(this); + } + } + /** * Disconnect this client. */