
Signature
Remove "user" from the email address to reply to the author.
This posting is provided "AS IS" with no warranties, and confers no rights
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
I tried what you suggested. I opened two streams and a copy of the jpg file
was created. this is what i tried.
myFileStream = new
FileStream(m_strFileName,FileMode.Open,FileAccess.Read,FileShare.Read);//an
instance of FileStream
myOutStream = new
FileStream(m_strFileName.Replace("DSC","ABH"),FileMode.OpenOrCreate,FileAcce
ss.Write,FileShare.None);
myOutStream.WriteByte(); myOutStream.Close(); myFileStream.Close();
2) Yes I can send other kind of data successfully. I am able to send text
messages to and fro client and server.
Following is the code snippet of client and server.
Server
FILE *pFile = NULL;//file pointer
BYTE recvbuf[1024];
pFile = fopen(strFileName,"w");//opens a file for writing if the file does
exist it will empty it
int bytesRecv = SOCKET_ERROR;//initializes to an error value.
//this a while loop that keep reading bytes till the terminating symbol is
not found in the stream
while( bytesRecv == SOCKET_ERROR || !boTermFound)
{//keep reading and writing bytes till you read the end of the message
bytesRecv = recv(AcceptSocket, (char*)recvbuf, 1024, 0 );
//have to check weather the last n bytes contain the terminator string
if (bytesRecv == 0 || bytesRecv == WSAECONNRESET )
{
AfxMessageBox( "Connection Closed");
return false;
break;
}
boTermFound = CheckForTerminator(strTermString,recvbuf,bytesRecv);
fwrite(recvbuf, sizeof(BYTE),bytesRecv, pFile);
}
fclose(pFile)
Client (.net compact c#)
-------------------------
FileStream myFileStream;
myFileStream = new
FileStream(m_strFileName,FileMode.Open,FileAccess.Read,FileShare.Read);//an
instance of FileStream
byte[] b = new byte[myFileStream.Length];//create a byte array to store
for(long i=0;i<myFileStream.Length;i++)
b[i] = (byte)myFileStream.ReadByte();
myFileStream.Close();
_socket.BeginSend(b, 0, b.Length,
SocketFlags.None, null, null);
// send the terminator
_asyncEvent.Reset();
_socket.BeginSend(Network.TerminatorBytes, 0,
Network.TerminatorBytes.Length, SocketFlags.None, _sendCallback, true);
//this is just code that indicates termination of data.
This is becoming a serious problem. My whole project depends on
succcessfully able to transfer jpg images. Please look into this.
Regards, Abhishek
> Can you try the following ?
>
[quoted text clipped - 45 lines]
> >
> > Abhishek Gattani
Feroze [MSFT] - 22 Jan 2004 02:28 GMT
I see some problems with your code:
1) In the client
a) You are calling BeginSend() with null for Callback/State, but I dont see
you calling EndSend() anywhere.
b) You are reading the file in byte by byte. It is faster to read in a
buffer at the same time. Or you can read the file in fixed chunks, and use
MemoryStream() to buffer it. Then you can read fixed size chunks from the
memorystream and write it to the socket.
2) The server:
a) You are making wrong assumptions about the recv() call. See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock
/recv_2.asp.
This function returns SOCKET_ERROR if it fails, and you have to call
WSAGetLastError() to find out what went wrong. So, your server should be:
bytesRecv = recv(AcceptSocket, (char*)recvbuf, 1024, 0 );
//have to check weather the last n bytes contain the terminator string
if (bytesRecv == SOCKET_ERROR )
{
DWORD error = WSAGetLastError();
if(error == WSAECONNRESET) {
AfxMessageBox( "Connection Closed");
return false;
break;
}
}
b) You are using "fopen" to create your file. The default fopen() mode is
"TEXT" mode, where it performs some translations. You should instead use the
"b" mode. Or better still, use CreateFile/WriteFile.

Signature
Remove "user" from the email address to reply to the author.
This posting is provided "AS IS" with no warranties, and confers no rights
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
> I tried what you suggested. I opened two streams and a copy of the jpg file
> was created. this is what i tried.
>
> myFileStream = new
FileStream(m_strFileName,FileMode.Open,FileAccess.Read,FileShare.Read);//an
> instance of FileStream
> myOutStream = new
FileStream(m_strFileName.Replace("DSC","ABH"),FileMode.OpenOrCreate,FileAcce
> ss.Write,FileShare.None);
> myOutStream.WriteByte(); myOutStream.Close(); myFileStream.Close();
[quoted text clipped - 32 lines]
> FileStream myFileStream;
> myFileStream = new
FileStream(m_strFileName,FileMode.Open,FileAccess.Read,FileShare.Read);//an
> instance of FileStream
> byte[] b = new byte[myFileStream.Length];//create a byte array to store
[quoted text clipped - 71 lines]
> > >
> > > Abhishek Gattani
avdijk - 06 Feb 2004 06:38 GMT
Don't you think it is possible that there occurs a format conversio
between the PC and Pocket PC.
I have a similar problem where I store a JPG in SQL, and when I try t
access the Image, I get an Exception.
I write the Stream to file on the Pocket PC, and when I browse the fil
on the Pocket PC it doesn't open, but when I open it with my PC it i
100%.
Any comments
avdij
Feroze [MSFT] - 23 Feb 2004 04:24 GMT
It is definitely possile. Especially if the PocketPc uses BigEndian, whereas
the PC uses LittleEndian. You should be mindful of this difference. Note
that I am not saying that the PocketPc uses BigEndian, you should confirm
that it does.

Signature
Remove "user" from the email address to reply to the author.
This posting is provided "AS IS" with no warranties, and confers no rights
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
> Don't you think it is possible that there occurs a format conversion
> between the PC and Pocket PC.
[quoted text clipped - 12 lines]
> ------------------------------------------------------------------------
> View this thread: http://www.mcse.ms/message296161.html