Socket Problem

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Socket Problem

Postby Frink » Mon Aug 17, 2009 11:18 am

I'm trying to get my android client to connect to my server.

The connection seems to be okay, but the client doesn't seem to be reading anything correctly.

Once connected, the server sends a HELLO message. The client doesn't seem to acknowledge it until the server disconnects the client (or server is closed). After which it seems to arrive immediately, followed by disconnection.

I don't think its a problem with the server (which isn't android) because I have made a VB program that connects and works with it fine.

As far as I know, the code should work fine (I've done it before in desktop Java) and it's the same as any examples I can find on the internet...

If anyone could shed some light, I'd very much appreciate it :)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. sock = new Socket(Finals.SERVER_HOST, Finals.SERVER_PORT);
  3.  
  4. DataInputStream inputstream = new DataInputStream(sock.getInputStream());
  5.  
  6.                        
  7.  
  8. Log.v("act", "socket open");
  9.  
  10.        
  11.  
  12. String received;                       
  13.  
  14. while((received = inputstream.readLine()) != null) {
  15.  
  16.         Log.v("act", "received");
  17.  
  18.         parseIncoming(received);
  19.  
  20. }
  21.  
  22.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
User avatar
Frink
Developer
Developer
 
Posts: 46
Joined: Sat Aug 15, 2009 7:42 pm

Top

Postby Frink » Mon Aug 17, 2009 11:53 am

Seem to have solved this, it's a bit dirty and I don't think it's the right way but, changing to this seemed to work.



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                         while(sock.isConnected()) {
  3.  
  4.                                 byte[] buffer = new byte[512];
  5.  
  6.                                 int length = inputstream.read(buffer);
  7.  
  8.                                 if(length > 0) {
  9.  
  10.                                         Log.v("act", "received");
  11.  
  12.                                         parseIncoming(buffer);
  13.  
  14.                                 }
  15.  
  16.                         }
  17.  
  18.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
User avatar
Frink
Developer
Developer
 
Posts: 46
Joined: Sat Aug 15, 2009 7:42 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Google Feedfetcher and 6 guests