It looks like you're new here. If you want to get involved, click one of these buttons!
-(void)viewDidLoad
{
[super viewDidLoad];
backGround.userInteractionEnabled=YES;
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError *error = nil;
if (![udpSocket bindToPort:0 error:&error]) //check ff of dit werkt!
{
return;
}
if (![udpSocket beginReceiving:&error])
{
return;
}
}
- (IBAction)sendData:(id)sender
{
NSString *msg = messageField.text;
NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding];
[self sendingRealData:data];
}
-(void)sendingRealData:(NSData *) Content
{
NSString *msg = [[NSString alloc] initWithData:Content encoding:NSUTF8StringEncoding];
NSLog(@\"msg is: %@\", msg);
NSString *host = [self getHost];
int port = [self getPort];
if ((port == 65536) && (host == @\"-1\"))
{
NSLog(@\"Port and IP are not filled in!\");
[self errorManag:2];
}
else if ((port == 65536) && (host != @\"-1\"))
{
NSLog(@\"return was -2\");
[self errorManag:1];
}
else if (host == @\"-1\")
{
NSLog(@\"return was -1\");
[self errorManag:0];
}
else
{
[udpSocket sendData:Content toHost:host port:port withTimeout:1 tag:tag];
NSLog(@\"Gestuurd\");
}
}
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
fromAddress:(NSData *)address
withFilterContext:(id)filterContext
{
NSLog(@\"niets.\");
NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (msg)
{
NSLog(@\"iets gekregen\");
}
else
{
NSLog(@\"Error conversion\");
//[self logError:@\"Error converting received data into UTF-8 String\"];
}
//NSString *test = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//NSLog(@\"%@\",test);
//[udpSocket sendData:data toAddress:address withTimeout:-1 tag:0];
NSLog(@\"HMMMM\");
messageField.text = [[NSString alloc] initWithFormat:@\"RE: %@\", msg];
}
Replies
This caused the mobile to listen to a random port instead of port 12345. Changed the binding to port 12345 and it works!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome