2
저는 서버 측과 클라이언트 측을 다루는 iPhone 앱을 작성하고 있습니다. 문제는 내가 내 애플 리케이션 (클라이언트 측)에서 내 자바 프로그램 (서버 측)으로 데이터를 보낼 수 없다는 것입니다. 나는 지금 막 붙어있어, 어떤 도움이 많이 감사 할 것입니다.obj-c 클라이언트에서 java 서버로 데이터를 전송할 수 없습니다.
내 OBJ-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\n" length:16];
int bytes = [outStream write:[self.data bytes] maxLength:[self.data length]];
내 Java 코드 (서버) :
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();
}
}
무슨 일입니다 내 서버에 내 응용 프로그램의 코드를 데이터를 보낼 때 측면이 결코 지나치지 않습니다
msg = in.readLine(). 앱 측에서 연결을 종료하면 수신 된 문자열이 null이라고 표시됩니다.
위치를'in'셨어요 :
같은 문자열 길이, 뭔가를 하드 코딩하지 않으려 고? –