Я изменил код клиента (Android studio: Java) Клиент :
@Override
protected Boolean doInBackground(final Bitmap... bitmap) {
Bitmap imageBitmap = bitmap[0];
try {
if (m_socket != null) m_socket.close();
m_socket = new Socket(m_Address, m_nPort);
if (imageBitmap != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] array = bos.toByteArray();
if(bSendData) { // send data
OutputStream out = m_socket.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.write(array, 0, array.length);
dos.flush();
dos.close();
}else // send length of data
{
m_pw = new PrintWriter(m_socket.getOutputStream());
m_pw.write(String.valueOf(array.length));
m_pw.flush();
m_pw.close();
}
}
m_socket.close();
if (imageBitmap != null) {
m_IsOPrationSuccuses = true;
publishProgress("Sending ID-Photo to the server successfully");
return Boolean.TRUE;
}
}
catch (IOException e) {
e.printStackTrace();
m_IsOPrationSuccuses = false;
publishProgress("Failed to connect to the server!"+ e.getMessage());
}
return Boolean.FALSE;
}
Я написал на стороне сервера в c ++ на OnReceive используется функция CSocket:
if (m_nCount == 1)
{
char pBuf[512];
int iBufSize = 512;
memset(pBuf, 0, sizeof(pBuf));
// get the temp of file path and create if doesnt exist
fpwImage = _wfsopen(GetFullIDImageTempPath(), L"wb", _SH_DENYNO);
m_nCount = 0;
int nRead = 1, nTotalRead = 0; ;
while (nRead > 0 )
{
nRead = m_sConnectSocket.Receive(pBuf, iBufSize);
fwrite(pBuf, 1, nRead, fpwImage);
nTotalRead += nRead;
TRACE(L"8\n Read[%d] nTotalRead [%d]\n",nRead, nTotalRead);
if (nRead == 0)
break;
}
if (nRead == 0) {
fclose(fpwImage);
m_nCount = 1;
}
}
Проблема в том, что изображение отсутствует из его частей. Есть ли какая-либо ошибка или отсутствует на сервере или клиенте? как я могу это исправить? Я использовал длину файла, полученного как текст от Клиента, но проблема все еще та же.