我正在写一个iPhone 应用程序, 处理服务器侧面和客户端。 我的问题在于我无法从我的应用程序( 用户侧面) 向我的 java 程序( 服务员侧面) 发送任何数据。 我现在有点卡住了, 任何帮助都会非常感激 。
我的boj-c代码( 用户名) :
- (BOOL) initConnection: (NSString *) ipAddr {
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)ipAddr, 4444, NULL, &writeStream);
if(!writeStream)
return NO;
outStream = (__bridge NSOutputStream *) writeStream;
[outStream setDelegate:self];
[outStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[outStream open];
self.data = [[NSData alloc] init];
return YES;
- (void) sendCommand: (NSString *) command {
NSLog(@"Command that was sent to method: %@", command);
self.data = [NSData dataWithBytes:@"This is a test
" length:16];
int bytes = [outStream write:[self.data bytes] maxLength:[self.data length]];
我的爪哇代码( 服务员) :
private void handleCommands() {
try {
do {
System.out.println("Right before reading socket");
msg = in.readLine();
System.out.println("Received: " + msg);
} while(!EOC);
} catch(IOException e) {
e.printStackTrace();
}
}
What happens is that when I send data from my app the code on my server side never gets past
msg = in.readLine(). When I terminate the connection on the app side it prints out that the string received was null.