Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Receiving data from UDP server on iOS app is not working from Linux server, but works

BACKGROUND: I made an IPhone socket application based on UDP. It works as a client and server while it communicates with a Linux [Ubuntu] server. I’m using a GCDAsyncUdpSocket to send and receive data. I also have a back-up server/client application on my Macbook to test/verify the socket communication application. It simply acts like the Linux [Ubuntu] server. It works perfect.

PROBLEM: I can’t receive any data from the Linux [Ubuntu] server.

DETAILS: I can successfully send data to the Linux server and it reacts/processes upon that data. But when the server sends replies or echoes, my iPhone app can't see/read it. A similar application I developed with a colleague for Android does read/see data from the server. Please see the code below. Cheers!
This is the code for it: .m file:

-(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];
}



maybe I have to add something so that it starts receiving? Or is it filtering something out??
Post edited by Melkon on

Replies

Sign In or Register to comment.