Why I can't send the message to my java server via obj-c?
Here is the question. I open a socket from my java server, and send a UTF
string using objective-c, it can't read. So, I am interested in what's
going wrong??:
First here is the java code:
DataInputStream in = new DataInputStream( server.getInputStream());
System.out.println(in.readUTF()); //Just holding, can't print out
Full source code is here:
http://www.tutorialspoint.com/java/java_networking.htm
Then, is my iOS client source code:
NSString *requestStrFrmt = @"HEAD / HTTP/1.0\r\nHost: %@\r\n\r\n";
NSString *requestStr = [NSString stringWithFormat:requestStrFrmt, HOST];
NSData *requestData = [requestStr dataUsingEncoding:NSUTF8StringEncoding];
[asyncSocket writeData:requestData withTimeout:-1.0 tag:0];
Full source code for iOS client:
https://github.com/robbiehanson/CocoaAsyncSocket
The file path I quote: CocoaAsyncSocket / GCD / Xcode / SimpleHTTPClient /
Mobile / SimpleHTTPClient / SimpleHTTPClientAppDelegate.m
I didn't do something fancy, just change the IP and port. And here is the
output:
Waiting for client on port 7780... Just connected to /192.168.1.31:55207
Yes, they can connect together, but the server can't read the string I send.
No comments:
Post a Comment