先贴上代码:
//
// 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 initialization
udpSocket = [[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进制发送出去啊!
发出去是什么有什么重要的吗 实际上传输的都是二进制代码,你要做的就是接收的时候再转换你想要的格式,格式转化函数基本每个语言都差不多的,以c为例sprintf ios应该也有类似的吧
同求啊!我也是想发16进制的
我现在在写一个APP(ios),网络服务器开发文档中写到,需要的格式00 4c 02 42 02 49 96 02 d2 [32个字节][32个字节] 4f 4b 05 我用 [udpSocket sendData:numberBundle toHost:@"xxx.xxx.xxx.xxx." port:xxxx withTimeout:-1 tag:0];发送,也是能迷茫啊