从iOS服务器上的UDP服务器接收数据不能从Linux服务器上工作,但从MacBook Pro工作

背景:我做了一个基于UDP的IP套接字应用程序。 它在与Linux [Ubuntu]服务器通信时作为客户端和服务器。 我正在使用GCDAsyncUdpSocket发送和接收数据。 我的Macbook上还有一个备份服务器/客户端应用程序来testing/validation套接字通信应用程序。 它只是像Linux [Ubuntu]服务器。 它工作完美。

问题:我无法从Linux [Ubuntu]服务器接收任何数据。

详细信息:我可以成功地将数据发送到Linux服务器,并对该数据作出反应/处理。 但是,当服务器发送回复或回声,我的iPhone应用程序无法看到/读取它。 我与一位Android同事开发的一个类似的应用程序确实从服务器读取/查看数据。 请参阅下面的代码。 干杯!

这是它的代码:.m文件:

-(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 convertion"); //[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]; } 

我发现我已经写了ViewDidLoad绑定到端口:0,因为这个build议是以前给我的。

这导致移动侦听一个随机端口,而不是端口12345.更改绑定到端口12345和工作!