Skip to content

Commit fe6ac5e

Browse files
committed
Merge branch 'dev'
2 parents cd7b502 + ba38c44 commit fe6ac5e

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

netcat/src/main/java/com/github/dddpaul/netcat/NetCat.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,10 @@ protected Result doInBackground( String... params )
222222
Log.d( CLASS_NAME, String.format( "Disconnecting from %s", getSocketRemoteString( socket )));
223223
if( socket instanceof Socket ) {
224224
( (Socket) socket).shutdownOutput();
225+
( (Socket) socket).close();
226+
} else {
227+
( (DatagramSocket) socket).close();
225228
}
226-
socket.close();
227229
socket = null;
228230
publishProgress( IDLE.toString() );
229231
}

netcat/src/main/java/com/github/dddpaul/netcat/ui/MainFragment.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import android.widget.EditText;
1717

1818
import com.github.dddpaul.netcat.Constants;
19-
import com.github.dddpaul.netcat.NetCater;
2019
import com.github.dddpaul.netcat.R;
2120
import com.github.dddpaul.netcat.Utils;
2221

@@ -48,7 +47,7 @@ public class MainFragment extends Fragment
4847
protected Button listenButton;
4948

5049
@InjectView( R.id.c_tcp_udp )
51-
protected CheckBox tcpUdpCheckbox;
50+
protected CheckBox udpCheckbox;
5251

5352
private SharedPreferences prefs;
5453
private Set<String> connectToSet;
@@ -99,15 +98,15 @@ protected void onConnectButtonClick()
9998
editor.putStringSet( Constants.CONNECT_TO_SET_KEY, connectToSet );
10099
editor.apply();
101100

102-
Proto proto = tcpUdpCheckbox.isChecked() ? Proto.TCP : Proto.UDP;
101+
Proto proto = udpCheckbox.isChecked() ? Proto.UDP : Proto.TCP;
103102
connectTo = proto + ":" + connectTo;
104103
EventBus.getDefault().post( new FragmentEvent( CONNECT, connectTo ) );
105104
}
106105

107106
@OnClick( R.id.b_listen )
108107
protected void onListenButtonClick()
109108
{
110-
Proto proto = tcpUdpCheckbox.isChecked() ? Proto.TCP : Proto.UDP;
109+
Proto proto = udpCheckbox.isChecked() ? Proto.UDP : Proto.TCP;
111110
String listenOn = proto + ":" + listenOnText.getText().toString();
112111
EventBus.getDefault().post( new FragmentEvent( LISTEN, listenOn ) );
113112
}

netcat/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
<string name="error_port_format">Digits is expected</string>
2424
<string name="label_text_to_send">Text to send:</string>
2525
<string name="label_received_text">Received text:</string>
26-
<string name="label_tcp_udp">Use UDP instead of the default TCP</string>
26+
<string name="label_tcp_udp">Use UDP instead of TCP (experimental)</string>
2727

2828
</resources>

netcat/src/test/java/com/github/dddpaul/netcat/NetCatTest.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import android.util.Log;
77

8+
import org.junit.After;
89
import org.junit.Assert;
910
import org.junit.Before;
1011
import org.junit.BeforeClass;
@@ -61,6 +62,13 @@ public void setUp() throws Exception
6162
inputFromProcess = INPUT_NC;
6263
}
6364

65+
@After
66+
public void tearDown() throws InterruptedException
67+
{
68+
disconnect();
69+
process.destroy();
70+
}
71+
6472
@Test
6573
public void testTCPConnect() throws IOException, InterruptedException
6674
{
@@ -110,7 +118,6 @@ public void startConnectTest( Proto proto ) throws InterruptedException, IOExcep
110118

111119
send();
112120
receive();
113-
disconnect();
114121
}
115122

116123
public void startListenTest( Proto proto ) throws InterruptedException, IOException
@@ -151,7 +158,6 @@ public void run()
151158
receive();
152159
send();
153160
}
154-
disconnect();
155161
}
156162

157163
@Override
@@ -243,21 +249,7 @@ public void receive() throws IOException, InterruptedException
243249
// Send string from external nc process
244250
process.getOutputStream().write( inputFromProcess.getBytes() );
245251
process.getOutputStream().flush();
246-
/*
247-
new Thread( new Runnable()
248-
{
249-
@Override
250-
public void run()
251-
{
252-
try {
253-
Thread.sleep( 500 );
254-
} catch( Exception e ) {
255-
e.printStackTrace();
256-
}
257-
process.destroy();
258-
}
259-
}).start();
260-
*/
252+
process.getOutputStream().close();
261253

262254
// Receive string from external nc process
263255
netCat.createOutput();

0 commit comments

Comments
 (0)