先贴上代码:
//
// UDPDemoViewController.m
// UDPDemo
//
// Created by Leo Lin on 3/12/14.
// Copyright (c) 2014 Leo Lin. All rights reserved.
//
#import "UDPDemoViewController.h"
@interface UDPDemoViewController ()
@end
@implementation UDPDemoViewController
-
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initializationudpSocket = [[AsyncUdpSocket alloc] initWithDelegate:self]; NSError *error = nil; if (![udpSocket bindToPort:0 error:&error]) { NSLog(@"Error binding: %@", error); //return; } [udpSocket receiveWithTimeout:-1 tag:0]; NSLog(@"Ready");
}
return self;
} (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)SendUDPMessage
{
NSString *host = @"192.168.1.103";
int port = 60000;
NSString *msg = @"iPhone";
NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding];
[udpSocket sendData:data toHost:host port:port withTimeout:-1 tag:tag];
}
@end
现在发送的是文本格式,我想怎么才能16进制发送出去啊!