ios socket与javasocket通信有关问题
ios socket与javasocket通信问题
请问有人用过AsyncSocket(客户端)与java socket(服务器端)通信吗?
我遇到这情况,服务器端收不到客户端的信息,客户端也收不到服务器返回的信息
但是客户端与服务器端的socket连接却是创建了,这问题是出在哪里呢
新手,请指教。。。
客户端(ios)代码
请问有人用过AsyncSocket(客户端)与java socket(服务器端)通信吗?
我遇到这情况,服务器端收不到客户端的信息,客户端也收不到服务器返回的信息
但是客户端与服务器端的socket连接却是创建了,这问题是出在哪里呢
新手,请指教。。。
客户端(ios)代码
//
// TestUdpClientAppDelegate.m
// TestUdpClient
//
// Created by Xie Wei on 11-6-5.
// Copyright 2011年 e-linkway.com. All rights reserved.
//
#import "TestTcpClientAppDelegate.h"
#import "AsyncUdpSocket.h"
#import "AsyncSocket.h"
#define SERVER_IP @"192.168.1.109"
//#define SERVER_IP @"127.0.0.1"
#define SERVER_PORT 3005
@implementation TestUdpClientAppDelegate
@synthesize window = _window;
@synthesize sendSocket = _sendSocket;
//发送短消息
-(IBAction)sendString
{
NSData *data = [NSData dataWithBytes:"This is a test\n" length:15];
static BOOL connectOK = NO;
if (!_sendSocket)
{
self.sendSocket = [[[AsyncSocket alloc] initWithDelegate: self] autorelease];
NSError *error;
connectOK = [_sendSocket connectToHost: SERVER_IP onPort: SERVER_PORT error: &error];
if (!connectOK)
{
NSLog(@"connect error: %@", error);
}else{
NSLog(@"connect succ");
}
[_sendSocket setRunLoopModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
}
if (connectOK)
{
[_sendSocket writeData: data withTimeout: -1 tag: 0];
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
float button_center_y = 20;
float button_center_offset = 50;
_sendButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
_sendButton.frame = CGRectMake(0, 0, 200, 30);
_sendButton.center = CGPointMake(320 / 2, button_center_y += button_center_offset);
[_sendButton addTarget: self action: @selector(sendString) forControlEvents: UIControlEventTouchUpInside];
[_sendButton setTitle: @"Send String" forState: UIControlStateNormal];
[self.window addSubview: _sendButton];
[self.window makeKeyAndVisible];
return YES;
}
#pragma mark - tcp
- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port