search

Home  >  Q&A  >  body text

Objective-c - How does the iOS client send pictures to the Java server through GCDAsyncSocket?

How does the iOS client send pictures to the Java server through GCDAsyncSocket?
The java server said to send it three times, the first time it sent the file name (utf), the second time it sent the file length (int), and the third time it sent the picture (bytes)
This is the code I also need, but The server can't receive my pictures? ?

             NSData *data = UIImageJPEGRepresentation(result, 0.1);
            [self createClientTcpSocket];
            
            NSData *nameDate = [@"图片名2.jpg" dataUsingEncoding:NSUTF8StringEncoding];
            [asyncsocket writeData:nameDate withTimeout:-1 tag:0];
            
            uint64_t length =(uint64_t) data.length;
            length = CFSwapInt64HostToBig(length);
            NSData *lengthdata = [NSData dataWithBytes:&length length:8];
            [asyncsocket writeData:lengthdata withTimeout:-1 tag:0];
            
            [asyncsocket writeData:data withTimeout:-1 tag:0];
            [asyncsocket readDataWithTimeout:-1 tag:0];
PHP中文网PHP中文网2782 days ago643

reply all(0)I'll reply

No reply
  • Cancelreply