0
소켓을 통해 iOS에서 Unity로 UIImage를 보내려고합니다. UIImage를 NSData로 변환하고 비동기 소켓을 통해 Unity의 서버에 보냅니다.iOS의 Unity C#에서 소켓을 통해 이미지를 바이트 단위로 수신합니다.
클라이언트 (iOS 앱)에서 모든 바이트를 수신하고이 바이트를 이미지로 변환하여 컴퓨터에 이미지로 저장하려고합니다. 파일에 모든 시간 오류가 발생했습니다. 비어 있거나 손상되었습니다.
iOS 쪽, Unity 쪽 또는 둘 다에서 오류가 발생했는지 알 수 없습니다. 유니티 측에서
UIImage *img = images[number];
NSData *dataImg = UIImagePNGRepresentation(img);
[asyncSocket writeData:dataImg withTimeout:-1 tag:1]; // Uses GCDA Async Socket library
[asyncSocket disconnectAfterWriting];
, 내가 가진 : 내 아이폰 OS 측에서
, 내가 가진 빈
// Data buffer for incoming data.
byte[] bytes = new Byte[1024];
// host running the application.
Debug.Log("Ip " + getIPAddress().ToString());
IPAddress[] ipArray = Dns.GetHostAddresses(getIPAddress());
IPEndPoint localEndPoint = new IPEndPoint(ipArray[0], 1755);
// Create a TCP/IP socket.
listener = new Socket(ipArray[0].AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
// Bind the socket to the local endpoint and
// listen for incoming connections.
try
{
listener.Bind(localEndPoint);
listener.Listen(10);
// Start listening for connections.
while (true)
{
Debug.Log("Client Connected");
Socket handler = listener.Accept();
while (true) {
bytes = new byte[1024];
int bytesRec = handler.Receive(bytes);
data += Encoding.ASCII.GetString(bytes,0,bytesRec);
Debug.Log("Bytes rec: " + bytesRec);
if (bytesRec <= 0) {
// Save image in folder from bytes
File.WriteAllBytes(@"images/img.png",bytes);
break;
}
}
//File.WriteAllBytes(@"images/prova.png",dataImg);
System.Threading.Thread.Sleep(1);
}
}
catch (Exception e)
{
Debug.Log(e.ToString());
}
}