ソケットを使用するアプリがあります
私のアプリケーションでは、ソケット接続を確立しようとしています。ソケットを接続した後、SOAP リクエストをサーバーに送信する必要があります。SOAP リクエストのサーバーへの送信に問題があります。コードを添付しました。これで私を助けてください
BOOL status;
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
urlString = @"hoegamestg.hogaming.info";
// urlString = @"247liveagent.hointeractive.com";
if (![urlString isEqualToString:@""])
{
NSURL *website = [NSURL URLWithString:urlString];
if (!website)
{
NSLog(@"%@ is not a valid URL", urlString);
status = NO;
}
else
{
NSLog(@"URL IS VALID%@",website );
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef) [website host], 5654, &readStream, &writeStream);
// CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef) urlString, 5654, &readStream, &writeStream);
//USE TOLL-FREE BRIDGING FOR CONVERTING CORE-FOUNDATION STREAMS TO NSSTREAMS.
self.inputStream = (__bridge_transfer NSInputStream *)readStream;
self.outputStream = (__bridge_transfer NSOutputStream *)writeStream;
//SET DELEGATES TO STREAMS.
[self.inputStream setDelegate:self];
[self.outputStream setDelegate:self];
//AVOID BLOCKING OPERATIONS BY SCHEDULING THEM ON TO RUN LOOPS.
[self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
//FINALLY OPEN THE STREAMS.
[self.inputStream open];
[self.outputStream open];
}
}......
デリゲート メソッドと SOAP リクエスト
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode{
// Start Logging events.
// NSString *str = [NSString stringWithFormat:@"%d",eventCode];
// NSMutableString *subscribeTableString;
NSData *data;
NSString *soapMessage = [[NSString alloc]init];
switch (eventCode) {
case NSStreamEventNone:
NSLog(@"NSStreamEventNone");
break;
case NSStreamEventOpenCompleted:
NSLog(@"NSStreamEventOpenCompleted");
break;
case NSStreamEventHasBytesAvailable:
NSLog(@"NSStreamEventHasBytesAvailable");
[self readDataFromStream];
break;
case NSStreamEventHasSpaceAvailable:
NSLog(@"NSStreamEventHasSpaceAvailable");
soapMessage=[soapMessage stringByAppendingString:[NSString stringWithFormat:@"<subscribe channel=\"table-bc7ire5oi4uhetfd\" ><player id=\"%@\" />",socketValue ]];
// soapMessage=[soapMessage stringByAppendingString:[NSString stringWithFormat:@"<subscribe channel=\"table-bc7ire5oi4uhetfd\" ><player id= \"c2da1a80c52542dd\" />" ]];
soapMessage =[soapMessage stringByAppendingString:[NSString stringWithFormat:@"<sessionid id=\"%@\"",socketname]];
soapMessage =[soapMessage stringByAppendingString:[NSString stringWithFormat:@"></sessionid></subscribe>"]];
NSLog(@"THE STRING IS : %@", soapMessage);
data = [[NSData alloc] initWithData:[soapMessage dataUsingEncoding:NSASCIIStringEncoding]];
[self.outputStream write:[data bytes] maxLength:[data length]];
NSLog(@"THE STRING IS : %@", self.outputStream);
[self setMWriteData:[NSData dataWithBytes:(__bridge const void*)soapMessage length:
[soapMessage length]]];
[self writeDataToStream];
// <subscribe channel="table-l8i2hq4jo2hjj9ca"><player id="b82fe3c52020494b" /><sessionid id="246421321cc873d080b550bcc555de0e9d9d29d8cba6f243ec56d38c5785"></sessionid></subscribe>
break;
case NSStreamEventErrorOccurred:
NSLog(@"NSStreamEventErrorOccurred");
NSLog(@"THE ERROR IS : %@", [aStream streamError]);
break;
case NSStreamEventEndEncountered:
break;
default:
break;
}
}