mardi 30 juin 2015

How to send image to server using UDP Client Programm in iOS?

 - (IBAction)sendBuf:(id)sender
   {
    _imageVw.image=nil;

    if ([[bufOut text] length] > 0)
    {
        NSString *requestStr = [bufOut text];
        NSData *requestData = [requestStr dataUsingEncoding:NSUTF8StringEncoding];
        [asyncSocket writeData:requestData withTimeout:-1.0 tag:0];//Writing to stream data
//        [asyncUDPSocket sendData:requestData withTimeout:-1.0 tag:1];
        [self debugPrint:[NSString stringWithFormat:@"Sent:  \n%@",requestStr]];
    }
    else
    {
        UIImage *image = [UIImage imageNamed:@"images.jpeg"];
        NSData *data = UIImagePNGRepresentation(image);

        _imageVw.image=[UIImage imageWithData:data];
        [asyncSocket writeData:data withTimeout:-1.0 tag:0];

    }
    [self startRead];
}

I have done this code for sending text & image . Text was sending successfully but image was not sending properly.I have done this demo from this here. I am unable to find where was the issue ? And the server was running in c# .net. It will handle both tcp & udp.

Aucun commentaire:

Enregistrer un commentaire