Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old August 24th, 2012, 06:56 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2012
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Angry Android TCP Recieve Failure

I am connecting to a server on my network written in C#. The data sent from the android device is recieved
by the server and a reply is succesfully sent but the android code timesout and never gets the return data.

I have tested that the C# server can communicate and reply with a C# client.

I have studied the network traffic using Wireshark when using both the C# server-android client and C# server-C#
client and it appears that the android device acknowledges(ACK) the reply data but my code never recieves it.

I have the code running in a thread so running it on Android 4.0 doesn't error out but I have tried running it on
Android 2.2 with exactly the same behaviour(or lack of it). Also I have run it on 2 different android devices.

(AndroidManifest.xml)
Code:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
(My Code)
Code:
private static final int TCP_SERVER_PORT = 3000;
private static final String TCP_SERVER_IP = "192.168.1.55";

try {
	SocketAddress socketAddress = new InetSocketAddress(serverAddr, TCP_SERVER_PORT);
	Socket s2 = new Socket();
	s2.connect(socketAddress);

	BufferedReader in = new BufferedReader(new InputStreamReader(s2.getInputStream()));
	BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s2.getOutputStream()));
		
	//send output msg
	String outMsg = "TCP connecting to " + TCP_SERVER_PORT + System.getProperty("line.separator"); 			
	out.write(outMsg);
	out.flush();
		
	//accept server response	
	String inMsg = in.readLine();

		s2.close();
		
	} catch (UnknownHostException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	}

liggerbott is offline  
Reply With Quote
sponsored links
Old August 24th, 2012, 08:23 AM   #2 (permalink)
Junior Member
 
Join Date: Aug 2012
Location: Athens, Greece
Posts: 42
 
Device(s):
Carrier: Not Provided

Thanks: 6
Thanked 7 Times in 7 Posts
Default

Are you sure that the server sends a full line (a string terminated with a new line character)? You are using BufferedReader.readLine(), which blocks the program flow until a full line is received.
Kostas G is offline  
Reply With Quote
Old August 24th, 2012, 09:46 PM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2012
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

That sounds as if it could be the problem, I thought it would be something simple. I will test it it shortly and report back. Thank you, hopefully now my hair will grow back
liggerbott is offline  
Reply With Quote
Old August 24th, 2012, 10:12 PM   #4 (permalink)
New Member
Thread Author (OP)
 
Join Date: Aug 2012
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

All fixed. How stupid do I feel now? Been playing with this for ages...
liggerbott is offline  
Reply With Quote
Reply
Tags
android, tcp


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 03:00 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.