public void run() { try { // Wait for a connection. SocketConnection sc = (SocketConnection) scn.acceptAndOpen(); InputStream is = sc.openInputStream(); OutputStream os = sc.openOutputStream(); int ch = 0; int count = 0; while (ch != -1) { ch = is.read(); if (ch == -1) { break; } os.write(ch); os.flush(); count++; } } catch (IOException e) { e.printStackTrace(); } finally { finished = true; } }
public void testServerSocketConnection() throws IOException, InterruptedException { ServerSocketConnection scn = (ServerSocketConnection) Connector.open("socket://:" + serverPort); try { ServerThread t = new ServerThread(scn); t.start(); while (!t.started) { Thread.sleep(20); } assertEquals("Server Port", Integer.valueOf(serverPort).intValue(), scn.getLocalPort()); assertNotEquals("Server Host", "0.0.0.0", scn.getLocalAddress()); assertNotEquals("Server Host", "localhost", scn.getLocalAddress()); // assertNotEquals("Server Host", "127.0.0.1", scn.getLocalAddress()); runLoopbackTest("socket://" + scn.getLocalAddress() + ":" + scn.getLocalPort()); } finally { scn.close(); } }