diff --git a/src/org/ice4j/pseudotcp/PseudoTCPBase.java b/src/org/ice4j/pseudotcp/PseudoTCPBase.java index dc28cd1..3cc770c 100755 --- a/src/org/ice4j/pseudotcp/PseudoTCPBase.java +++ b/src/org/ice4j/pseudotcp/PseudoTCPBase.java @@ -1089,6 +1089,7 @@ public class PseudoTCPBase if (nFree < m_slist.get(0).len) { m_slist.get(0).len -= nFree; + m_slist.get(0).seq += nFree; nFree = 0; } else @@ -1764,7 +1765,7 @@ public class PseudoTCPBase } m_mss = m_mtu_advise - PACKET_OVERHEAD; // !?! Should we reset m_largest here? - logger.log(Level.INFO, "Adjusting mss to " + m_mss + " bytes"); + logger.log(Level.FINE, "Adjusting mss to " + m_mss + " bytes"); // Enforce minimums on ssthresh and cwnd m_ssthresh = Math.max(m_ssthresh, 2 * m_mss); diff --git a/src/org/ice4j/pseudotcp/PseudoTcpJavaSocket.java b/src/org/ice4j/pseudotcp/PseudoTcpJavaSocket.java new file mode 100644 index 0000000..889c928 --- /dev/null +++ b/src/org/ice4j/pseudotcp/PseudoTcpJavaSocket.java @@ -0,0 +1,26 @@ +/* + * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * Maintained by the Jitsi community (https://jitsi.org). + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package org.ice4j.pseudotcp; + +import java.net.*; + +/** + * + * @author Pawel Domas + */ +public class PseudoTcpJavaSocket extends Socket { + public PseudoTcpJavaSocket(long conv_id) throws SocketException { + super(new PseudoTcpSocketImpl(conv_id)); + } + + public PseudoTcpJavaSocket(long conv_id, DatagramSocket socket) + throws SocketException { + super(new PseudoTcpSocketImpl(conv_id, socket)); + } + +} diff --git a/src/org/ice4j/pseudotcp/PseudoTcpSocket.java b/src/org/ice4j/pseudotcp/PseudoTcpSocketImpl.java similarity index 75% rename from src/org/ice4j/pseudotcp/PseudoTcpSocket.java rename to src/org/ice4j/pseudotcp/PseudoTcpSocketImpl.java index fa071f8..4cb2a3c 100755 --- a/src/org/ice4j/pseudotcp/PseudoTcpSocket.java +++ b/src/org/ice4j/pseudotcp/PseudoTcpSocketImpl.java @@ -9,9 +9,13 @@ package org.ice4j.pseudotcp; import java.io.*; import java.net.*; +import java.util.HashMap; +import java.util.Map; import java.util.logging.*; -public class PseudoTcpSocket implements IPseudoTcpNotify +public class PseudoTcpSocketImpl +extends SocketImpl +implements IPseudoTcpNotify { /** * The logger. @@ -25,7 +29,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify /** * Datagram socket used to handle network operations */ - private final DatagramSocket socket; + private DatagramSocket socket; /** * Current socket address of remote socket that we are connected to */ @@ -62,12 +66,23 @@ public class PseudoTcpSocket implements IPseudoTcpNotify */ private IOException exception; + + /** + * + */ + private PseudoTcpInputStream inputStream; + + /** + * + */ + private PseudoTcpOutputStream outputstream; + /** * * @param conv_id conversation id, must be the same on both sides * @param sock datagram socket used for network operations */ - public PseudoTcpSocket(long conv_id, DatagramSocket sock) + public PseudoTcpSocketImpl(long conv_id, DatagramSocket sock) { pseudoTcp = new PseudoTCPBase(this, conv_id); this.socket = sock; @@ -80,7 +95,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify * @param conv_id conversation id, must be the same on both sides * @throws SocketException */ - public PseudoTcpSocket(long conv_id) + public PseudoTcpSocketImpl(long conv_id) throws SocketException { this(conv_id, new DatagramSocket()); @@ -93,7 +108,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify * @param local_port * @throws SocketException */ - public PseudoTcpSocket(long conv_id, int local_port) + public PseudoTcpSocketImpl(long conv_id, int local_port) throws SocketException { this(conv_id, new DatagramSocket(local_port)); @@ -108,14 +123,125 @@ public class PseudoTcpSocket implements IPseudoTcpNotify * @throws SocketException * @throws UnknownHostException */ - public PseudoTcpSocket(long conv_id, String local_ip, int local_port) + public PseudoTcpSocketImpl(long conv_id, String local_ip, int local_port) throws SocketException, UnknownHostException { this(conv_id, new DatagramSocket(local_port, InetAddress.getByName(local_ip))); } + + /** + * Sets the MTU parameter for this socket + * @param mtu + */ + public void setMTU(int mtu) + { + this.pseudoTcp.NotifyMTU(mtu); + } + + /** + * Sets debug name that will be displayed in log messages for this socket + * @param debugName + */ + public void setDebugName(String debugName) + { + this.pseudoTcp.debugName = debugName; + } + /** + * Creates either a stream or a datagram socket. + * @param stream if true, create a stream socket; otherwise, create a datagram socket. + * @throws IOException if an I/O error occurs while creating the socket. + */ + protected void create(boolean stream) + throws IOException + { + //no effect + } + + /** + * Connects this socket to the specified port on the named host. + * @param host the name of the remote host. + * @param port the port number. + * @throws IOException + */ + protected void connect(String host, int port) + throws IOException + { + Connect(new InetSocketAddress(InetAddress.getByName(host), port), 0); + } + + /** + * Connects this socket to the specified port number on the specified host. + * @param address the IP address of the remote host. + * @param port the port number. + * @throws IOException if an I/O error occurs when attempting a connection. + */ + protected void connect(InetAddress address, int port) + throws IOException + { + connect(address.getHostAddress(), port); + } + + /** + * Connects this socket to the specified port number on the specified host. + * A timeout of zero is interpreted as an infinite timeout. + * The connection will then block until established or an error occurs. + * @param address the Socket address of the remote host. + * @param timeout the timeout value, in milliseconds, or zero for no timeout. + * @throws IOException if an I/O error occurs when attempting a connection. + */ + protected void connect(SocketAddress address, int timeout) + throws IOException + { + InetSocketAddress inetAddr = (InetSocketAddress) address; + Connect(inetAddr, timeout); + } + + /** + * Binds this socket to the specified port number on the specified host. + * @param host the IP address of the remote host. + * @param port the port number. + * @throws IOException + */ + public void bind(InetAddress host, int port) + throws IOException + { + if(socket != null) + socket.close(); + InetSocketAddress newAddr = new InetSocketAddress(host.getHostAddress(),port); + this.socket = new DatagramSocket(newAddr); + } + + /** + * Sets the maximum queue length for incoming connection + * indications (a request to connect) to the count argument. + * If a connection indication arrives when the queue is full, + * the connection is refused. + * @param backlog the maximum length of the queue. + * @throws IOException if an I/O error occurs when creating the queue. + */ + protected void listen(int backlog) + throws IOException + { + throw new UnsupportedOperationException("Not supported yet."); + } + + private Map options = new HashMap(); + public void setOption(int optID, Object value) + throws SocketException + { + options.put(optID, value); + } + + public Object getOption(int optID) + throws SocketException + { + return options.get(optID); + } + + /** * Start connection procedure * @@ -126,10 +252,12 @@ public class PseudoTcpSocket implements IPseudoTcpNotify public void Connect(InetSocketAddress remoteAddress, long timeout) throws IOException { + logger.fine("Connecting to "+remoteAddress); this.remoteAddr = remoteAddress; StartThreads(); pseudoTcp.Connect(); UpdateClock(); + boolean noTimeout = timeout <= 0; try { long elapsed = 0; @@ -138,7 +266,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify synchronized (state_notify) { while (pseudoTcp.getState() != PseudoTcpState.TCP_ESTABLISHED - && elapsed < timeout) + && (noTimeout ? true : (elapsed < timeout)) ) { long start = System.currentTimeMillis(); state_notify.wait(timeout); @@ -153,27 +281,11 @@ public class PseudoTcpSocket implements IPseudoTcpNotify } catch (InterruptedException ex) { - Close(); + close(); throw new IOException("Connect aborted"); } } - - /** - * Start connection procedure - * - * @param ip destination ip address - * @param port destination port - * @param timeout for this operation in ms - * @throws IOException - */ - public void Connect(String ip, int port, long timeout) - throws IOException - { - //this.remoteAddr = InetAddress.getByName(ip); - //this.remotePort = port; - Connect(new InetSocketAddress(InetAddress.getByName(ip), port), timeout); - } - + /** * Blocking method waits for connection. * @@ -183,7 +295,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify public void Accept(int timeout) throws IOException { - try + try { StartThreads(); PseudoTcpState state = pseudoTcp.getState(); @@ -210,7 +322,20 @@ public class PseudoTcpSocket implements IPseudoTcpNotify throw e; } } - + + /** + * Accepts a connection. + * @param s the accepted connection. + * @throws IOException if an I/O error occurs when accepting the connection. + */ + protected void accept(SocketImpl s) + throws IOException + { + //TODO: not sure how this should work + int timeout = 5000; + Accept(timeout); + } + /** * * @return current TCP state @@ -239,6 +364,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify pseudoTcp.NotifyClock(System.currentTimeMillis()); receiveThread = new Thread(new Runnable() { + @Override public void run() { ReceivePackets(); @@ -246,6 +372,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify }, "PseudoTcpReceiveThread"); clockThread = new Thread(new Runnable() { + @Override public void run() { RunClock(); @@ -257,45 +384,13 @@ public class PseudoTcpSocket implements IPseudoTcpNotify clockThread.start(); } - /** - * Shutdown the socket - * - * @throws IOException - */ - public void Close() throws IOException - { - try - { - pseudoTcp.Close(true); - //System.out.println("ON CLOSE: in flight "+pseudoTcp.GetBytesInFlight()); - //System.out.println("ON CLOSE: buff not sent "+pseudoTcp.GetBytesBufferedNotSent()); - OnTcpClosed(pseudoTcp, null); - socket.close(); - JoinAllThreads(); - //UpdateClock(); - //TODO: closing procedure - //Here the thread should be blocked until TCP - //reaches CLOSED state, but there's no closing procedure - /* - * synchronized(state_notify){ while(pseudoTcp.getState() != - * PseudoTcpState.TCP_CLOSED){ try { state_notify.wait(); } catch - * (InterruptedException ex) { throw new IOException("Close - * connection aborted"); } } } - */ - } - catch (InterruptedException ex) - { - throw new IOException("Closing socket interrupted", ex); - } - - } - /** * Implements @link(IPseudoTcpNotify) * Called when TCP enters connected state. * * @param tcp */ + @Override public void OnTcpOpen(PseudoTCPBase tcp) { logger.log(Level.FINE, "tcp opened"); @@ -313,6 +408,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify * * @param tcp */ + @Override public void OnTcpReadable(PseudoTCPBase tcp) { //release all thread blocked at read_notify monitor @@ -330,6 +426,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify * * @param tcp */ + @Override public void OnTcpWriteable(PseudoTCPBase tcp) { @@ -350,6 +447,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify * @param tcp * @param e */ + @Override public void OnTcpClosed(PseudoTCPBase tcp, IOException e) { if (e != null) @@ -409,6 +507,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify * @param len * @return */ + @Override public WriteResult TcpWritePacket(PseudoTCPBase tcp, byte[] buffer, int len) { if (logger.isLoggable(Level.FINEST)) @@ -417,6 +516,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify } try { + //TODO: in case the packet is too long it should return WR_TOO_LARGE DatagramPacket packet = new DatagramPacket(buffer, len, remoteAddr); socket.send(packet); return WriteResult.WR_SUCCESS; @@ -479,7 +579,7 @@ public class PseudoTcpSocket implements IPseudoTcpNotify if (runReceive) { logger.log(Level.SEVERE, - "ReceivePackets exception: " + ex); + "ReceivePackets exception: " + ex); pseudoTcp.closedown(ex); } break; @@ -536,14 +636,14 @@ public class PseudoTcpSocket implements IPseudoTcpNotify } } - private OutputStream outputstream; - + /** - * Lazy initialization for socket class - * - * @return output socket object + * Returns an output stream for this socket. + * @return an output stream for writing to this socket. + * @throws IOException if an I/O error occurs when creating the output stream. */ public OutputStream getOutputStream() + throws IOException { if (outputstream == null) { @@ -551,14 +651,15 @@ public class PseudoTcpSocket implements IPseudoTcpNotify } return outputstream; } - private PseudoTcpInputStream inputStream; + /** - * Lazy initialization for socket class - * - * @return output socket object + * Returns an input stream for this socket. + * @return a stream for reading from this socket. + * @throws IOException */ public InputStream getInputStream() + throws IOException { if (inputStream == null) { @@ -567,6 +668,62 @@ public class PseudoTcpSocket implements IPseudoTcpNotify return inputStream; } + /** + * Returns the number of bytes that can be read from this socket without blocking. + * @return the number of bytes that can be read from this socket without blocking. + * @throws IOException if an I/O error occurs when determining the number of bytes available. + */ + protected int available() + throws IOException + { + return getInputStream().available(); + } + + /** + * Closes this socket. + * @throws IOException + */ + public void close() + throws IOException + { + try + { + pseudoTcp.Close(true); + //System.out.println("ON CLOSE: in flight "+pseudoTcp.GetBytesInFlight()); + //System.out.println("ON CLOSE: buff not sent "+pseudoTcp.GetBytesBufferedNotSent()); + OnTcpClosed(pseudoTcp, null); + socket.close(); + JoinAllThreads(); + //UpdateClock(); + //TODO: closing procedure + //Here the thread should be blocked until TCP + //reaches CLOSED state, but there's no closing procedure + /* + * synchronized(state_notify){ while(pseudoTcp.getState() != + * PseudoTcpState.TCP_CLOSED){ try { state_notify.wait(); } catch + * (InterruptedException ex) { throw new IOException("Close + * connection aborted"); } } } + */ + } + catch (InterruptedException ex) + { + throw new IOException("Closing socket interrupted", ex); + } + } + + /** + * Send one byte of urgent data on the socket. The byte to be sent is the low eight bits of the parameter + * @param data The byte of data to send + * @throws IOException if there is an error sending the data. + */ + protected void sendUrgentData(int data) + throws IOException + { + throw new RuntimeException("Sending urgent data is not supported"); + } + + + /** * This class implements @link(InputStream) * */ diff --git a/test/org/ice4j/StunTestSuite.java b/test/org/ice4j/StunTestSuite.java index 29c6921..c1abb2e 100644 --- a/test/org/ice4j/StunTestSuite.java +++ b/test/org/ice4j/StunTestSuite.java @@ -73,6 +73,12 @@ public class StunTestSuite suite.addTestSuite(org.ice4j.stunclient.StunAddressDiscovererTest.class); suite.addTestSuite(org.ice4j.stunclient.StunAddressDiscovererTest_v6.class); suite.addTestSuite(org.ice4j.stunclient.StunAddressDiscovererTest_v4v6.class); + + //pseudotcp + suite.addTestSuite(org.ice4j.pseudotcp.PseudoTcpTestTransfer.class); + suite.addTestSuite(org.ice4j.pseudotcp.PseudoTcpTestPingPong.class); + suite.addTestSuite(org.ice4j.pseudotcp.PseudoTcpTestRecvWindow.class); + suite.addTestSuite(org.ice4j.pseudotcp.PseudoTcpStreamTest.class); return suite; } diff --git a/test/org/ice4j/pseudotcp/PseudoTcpStreamTest.java b/test/org/ice4j/pseudotcp/PseudoTcpStreamTest.java index 6076c69..62ed48a 100755 --- a/test/org/ice4j/pseudotcp/PseudoTcpStreamTest.java +++ b/test/org/ice4j/pseudotcp/PseudoTcpStreamTest.java @@ -23,7 +23,7 @@ public class PseudoTcpStreamTest extends MultiThreadSupportTest * The logger. */ private static final Logger logger = - Logger.getLogger(PseudoTCPBase.class.getName()); + Logger.getLogger(PseudoTcpStreamTest.class.getName()); public PseudoTcpStreamTest() { @@ -41,16 +41,18 @@ public class PseudoTcpStreamTest extends MultiThreadSupportTest long conv_id = 0; final int size = 1000000; int transferTimeout = 5000; - final PseudoTcpSocket server = new PseudoTcpSocket(conv_id, server_port); - final PseudoTcpSocket client = new PseudoTcpSocket(conv_id); + final PseudoTcpSocketImpl server = new PseudoTcpSocketImpl(conv_id); + final PseudoTcpSocketImpl client = new PseudoTcpSocketImpl(conv_id); + Thread serverThread = new Thread(new Runnable() { @Override public void run() { try - { - server.Accept(300); + { + server.bind(InetAddress.getLocalHost(), server_port); + server.accept(null); int rcvd = 0; while (rcvd != size) { @@ -80,11 +82,11 @@ public class PseudoTcpStreamTest extends MultiThreadSupportTest { try { - client.Connect("localhost", server_port, 30000); + client.connect("localhost", server_port); assertEquals(PseudoTcpState.TCP_ESTABLISHED, client.getState()); client.getOutputStream().write(new byte[size]); client.getOutputStream().flush(); - client.Close(); + client.close(); } catch (IOException ex) { @@ -127,7 +129,7 @@ public class PseudoTcpStreamTest extends MultiThreadSupportTest { try { - PseudoTcpSocket server = new PseudoTcpSocket(0); + PseudoTcpSocketImpl server = new PseudoTcpSocketImpl(0); server.Accept(10); fail("Should throw timeout exception"); } diff --git a/test/org/ice4j/pseudotcp/PseudoTcpTestRecvWindow.java b/test/org/ice4j/pseudotcp/PseudoTcpTestRecvWindow.java index e05a190..0a61796 100755 --- a/test/org/ice4j/pseudotcp/PseudoTcpTestRecvWindow.java +++ b/test/org/ice4j/pseudotcp/PseudoTcpTestRecvWindow.java @@ -84,7 +84,6 @@ public class PseudoTcpTestRecvWindow extends PseudoTcpTestBase ScheduleWriteAction(0); long transferTout = MaxTransferTime(dummy.length, kMinTransferRate); - System.out.println("Timeout: " + transferTout); boolean transfferInTime = assert_Disconnected_wait(transferTout); elapsed = PseudoTCPBase.Now() - start; StopClocks(); diff --git a/test/test/IcePseudoTcp.java b/test/test/IcePseudoTcp.java index 4c4aa5e..edfe440 100755 --- a/test/test/IcePseudoTcp.java +++ b/test/test/IcePseudoTcp.java @@ -30,7 +30,7 @@ public class IcePseudoTcp * The logger. */ private static final Logger logger = - Logger.getLogger(CheckList.class.getName()); + Logger.getLogger(IcePseudoTcp.class.getName()); private static long startTime; /** * Local job thread variable @@ -43,7 +43,7 @@ public class IcePseudoTcp /** * Test data size */ - private static final int TEST_BYTES_COUNT = 1000000; + private static final int TEST_BYTES_COUNT = 15000000; /** * Flag inidcates if STUN should be used */ @@ -164,7 +164,7 @@ public class IcePseudoTcp try { localJob = new LocalPseudoTcpJob( - localCandidate.getTransportAddress()); + localCandidate.getDatagramSocket()); } catch (UnknownHostException ex) { @@ -188,20 +188,14 @@ public class IcePseudoTcp * that Agent instances are to be explicitly prepared for * garbage collection. */ - ((Agent) evt.getSource()).free(); - if (localJob != null - && iceProcessingState == IceProcessingState.TERMINATED) + && iceProcessingState == IceProcessingState.TERMINATED) { - localJob.start(); - synchronized (localAgentMonitor) - { - localAgentMonitor.notifyAll(); - } + localJob.start(); } - else + synchronized (localAgentMonitor) { - System.exit(0); + localAgentMonitor.notifyAll(); } } } @@ -229,7 +223,7 @@ public class IcePseudoTcp { logger.log(Level.INFO, "Remote: Total ICE processing time: " - + (processingEndTime - startTime) + " ms"); + + (processingEndTime - startTime) + " ms "); Agent agent = (Agent) evt.getSource(); logger.log(Level.INFO, "Remote: Create pseudo tcp stream"); @@ -247,8 +241,8 @@ public class IcePseudoTcp try { remoteJob = new RemotePseudoTcpJob( - localCandidate.getTransportAddress(), - remoteCandidate.getTransportAddress()); + localCandidate.getDatagramSocket(), + remoteCandidate.getTransportAddress()); } catch (UnknownHostException ex) { @@ -273,19 +267,14 @@ public class IcePseudoTcp * that Agent instances are to be explicitly prepared for * garbage collection. */ - ((Agent) evt.getSource()).free(); if (remoteJob != null - && iceProcessingState == IceProcessingState.TERMINATED) + && iceProcessingState == IceProcessingState.TERMINATED) { - remoteJob.start(); - synchronized (remoteAgentMonitor) - { - remoteAgentMonitor.notifyAll(); - } + remoteJob.start(); } - else + synchronized (remoteAgentMonitor) { - System.exit(0); + remoteAgentMonitor.notifyAll(); } } } @@ -356,28 +345,27 @@ public class IcePseudoTcp { logger.log(Level.FINEST, "Remote thread join started"); remoteJob.join(); - logger.log(Level.FINEST, "Remote thread joined"); + logger.log(Level.FINEST, "Remote thread joined"); } + remotePeer.free(); if (localJob != null) { logger.log(Level.FINEST, "Local thread join started"); localJob.join(); - logger.log(Level.FINEST, "Local thread joined"); + logger.log(Level.FINEST, "Local thread joined"); } + localAgent.free(); System.exit(0); } private static class LocalPseudoTcpJob extends Thread implements Runnable { - private InetSocketAddress transportAddr; + private DatagramSocket dgramSocket; - public LocalPseudoTcpJob(InetSocketAddress transportAddr) + public LocalPseudoTcpJob(DatagramSocket socket) throws UnknownHostException { - //This is required because of can not bind exception on Linux - InetAddress locIP = InetAddress.getByName( - transportAddr.getAddress().getHostAddress()); - this.transportAddr = new InetSocketAddress(locIP, transportAddr.getPort()); + this.dgramSocket = socket; } @Override @@ -387,9 +375,12 @@ public class IcePseudoTcp try { logger.log(Level.INFO, - "Local pseudotcp is using: " + transportAddr); - PseudoTcpSocket socket = new PseudoTcpSocket( - 0, new DatagramSocket(transportAddr)); + "Local pseudotcp is using: " + + dgramSocket.getLocalSocketAddress()); + PseudoTcpSocketImpl socket = new PseudoTcpSocketImpl( + 1073741824, dgramSocket); + socket.setMTU(1500); + socket.setDebugName("L"); socket.Accept(5000); byte[] buffer = new byte[TEST_BYTES_COUNT]; int read = 0; @@ -399,7 +390,7 @@ public class IcePseudoTcp logger.log(Level.FINEST, "Local job read: " + read); } //TODO: close when all received data is acked - //socket.Close(); + //socket.close(); } catch (IOException e) { @@ -411,18 +402,14 @@ public class IcePseudoTcp private static class RemotePseudoTcpJob extends Thread implements Runnable { - private InetSocketAddress transportAddr; + private DatagramSocket dgramSocket; private InetSocketAddress peerAddr; - public RemotePseudoTcpJob(InetSocketAddress transportAddr, + public RemotePseudoTcpJob(DatagramSocket socket, InetSocketAddress peerAddr) throws UnknownHostException { - //This is required because of can not bind exception on Linux - //InetAddress locIP = InetAddress.getByName("127.0.0.1"); - InetAddress locIP = InetAddress.getByName( - transportAddr.getAddress().getHostAddress()); - this.transportAddr = new InetSocketAddress(locIP, transportAddr.getPort()); + this.dgramSocket = socket; this.peerAddr = peerAddr; } @@ -433,16 +420,21 @@ public class IcePseudoTcp try { logger.log(Level.INFO, - "Remote pseudotcp is using: " + transportAddr); - PseudoTcpSocket socket = new PseudoTcpSocket( - 0, new DatagramSocket(transportAddr)); + "Remote pseudotcp is using: " + + dgramSocket.getLocalSocketAddress() + +" and will comunicate with: " + peerAddr); + PseudoTcpSocketImpl socket = new PseudoTcpSocketImpl( + 1073741824, dgramSocket); + socket.setMTU(1500); + socket.setDebugName("R"); long start, end; start = System.currentTimeMillis(); socket.Connect(peerAddr, 5000); byte[] buffer = new byte[TEST_BYTES_COUNT]; socket.getOutputStream().write(buffer); socket.getOutputStream().flush(); - socket.Close(); + //Socket will be closed by the iceAgent + //socket.close(); end = System.currentTimeMillis(); logger.log(Level.INFO, "Transferred " + TEST_BYTES_COUNT @@ -456,33 +448,4 @@ public class IcePseudoTcp } } - /* - * static void TransferWithTcp() { try { final ServerSocket server = new - * ServerSocket(); int testPort = 60000; server.bind(new - * InetSocketAddress(testPort)); final Socket client = new Socket(); new - * Thread(new RunnableImpl(client, server)).start(); long start = - * System.currentTimeMillis(); byte[] serverBuffer = new - * byte[TEST_BYTES_COUNT]; Socket clientAtServer = server.accept(); int - * received = 0; do { received += - * clientAtServer.getInputStream().read(serverBuffer); } while (received < - * serverBuffer.length); long end = System.currentTimeMillis(); - * logger.log(Level.INFO, "Transferred " + received + " bytes in " + ((end - - * start) / 1000) + " sec"); } catch (IOException ex) { - * Logger.getLogger(IcePseudoTcp.class.getName()).log(Level.SEVERE, null, - * ex); } - * - * } - * - * static class RunnableImpl implements Runnable { private final Socket - * client; private final ServerSocket server; - * - * public RunnableImpl(Socket client, ServerSocket server) { this.client = - * client; this.server = server; } - * - * public void run() { try { client.connect(server.getLocalSocketAddress()); - * client.getOutputStream().write(new byte[TEST_BYTES_COUNT]); } catch - * (IOException ex) { - * Logger.getLogger(IcePseudoTcp.class.getName()).log(Level.SEVERE, null, - * ex); } } } - */ }