TCP Socket communication between iOS app and Android app -
Samsung Galaxy S is the need to communicate with each other over WiFi for iOS app on iPhone and Android app on the 3 network.
I am using cocoaSinks socket
library in the iOS app and java.net.Socket
in the Android app.
== iOS App part ==
- (minus) socket (Jiseedisinksset *) from didAcceptNewSocket: (GCDAsyncSocket *) newSocket {[clientSocketList addObject: newSocket]; NSMutableDictionary * newClientInfo = [[NSMutableDictionary alloc] init]; [NewClientInfo setObject: @ "0" for: @ "status"]; [Client Infight Add Object: Nuclear Inc]; [New Socket ReidataToddata: [GCDAsyncSocket CRLFData] with timeout: -1 tag: 0]; } - Write (zero) data: (NSDT *) for data: (gcdsynxset *) sock {NSMutableData * dataWithLine = [data incorrect cop]; [DataWithlineEpendance: [GCDDConsetCRLFdata]]; [Hundred data to write: timeout with datawithline: -1 tag: 0]; } {/ Code> == Android Part ==
Public Boolean Connect Server (try {socket = new socket (SOMEIP, SOMEPORT); BinaryInput = socket.getInputStream (); This.input = new BufferedReader (new InputStreamReader (binary input)); Out = new print Waitr (new Bfed Waitr (new Autputstrym water (Soketkgetotputstrym ())), is true;} catch (Exception e) {EkprintStackTrace ();} new Thread (new Rnnabl) {@ Override public Boyd run () {while (status! = STATUS_STOPPED) {try string = input.readLine (); // doing stuff} catch (IOException e) {e.printStackTrace ();}}}}). start (); } Public Zero send message (string message) {out.println (message); }
In the code above, the iOS app is a server and the Android app is a customer.
I intend to do the above code
-
Android app sends messages and the iOS app receives it from each message with the new line character Is recognized. The Android app sends a message through the println
method and the iOS app, until the CRLF (new line) character is not received.
-
The iOS app sends messages and the Android app receives it. Each message is identified by the new line character. The iOS app finally sends messages by attaching CRLF and receives messages by the Android app readline
method.
The problem is the obvious occurs when Android app sends message is not called Risevrdeta representatives iOS app is a thing that iOS App socket streaming CRLF can not be eligible.
I tried to send messages from the Android app by adding the CRLF bytes ([0x0d, 0x0a]) after the real app, but no luck.
In Java / Android, PrintWriter.println ()
OS-specific line brake writes the Siarelf
Windows line breaks Android, it requires instead LF
uses code that iOS reader only LF
, it will never be triggered.
Out.print (Message + "\ r \ n"); }
Comments
Post a Comment