On Sun, Nov 14, 2010 at 2:11 AM, bobetko <[email protected]> wrote:
> I am trying to write client for Android which is supposed to
> communicate with PC server application on local network.
> Server app is written by my friend in C#. Currently there is an iPhone
> app that is using this server application with no problems.
>
> I have very simple code for TCP client:
>
> 1. Socket s = new Socket(server, port);
> 2. OutputStream out = s.getOutputStream();
> 3. PrintWriter output = new PrintWriter(out);
> 4. output.println("ACTION=Next&VALUE=0&");
> 5. BufferedReader input = new BufferedReader(new
> InputStreamReader(s.getInputStream()));
> 6. String st = input.readLine();
>
> I went through many TCP implementation examples, and they are all
> similar. Pretty much like my code above.
> My app freezes on line 6 when I try to read response from the server.
> It doesn't cause any errors (no exceptions), nothing shows in
> debugger, just timeout error after awhile. Server is supposed to
> return string <OK> after executing my action in line 4.
> I don't understand why this code hangs. Input is not NULL (I've
> checked it). I would expect some exception to be thrown or simply
> empty string to be returned.
How did you check, whether the input is not NULL?
Can you verify that the server actually receives your "ACTION=Next..." string ?
Could you also verify, what does
Socket.isConnected() returns?
If FALSE, try the folowing:
s= new Socket();
s.connect(new InetSocketAddress("host_as_string", port_as_int));
--
Daniel Drozdzewski
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en