Click here to Skip to main content
15,912,400 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how can I respond Enter Event in a editbox? Pin
JohnnyG4-Aug-02 12:07
JohnnyG4-Aug-02 12:07 
GeneralSetFont Pin
Anonymous4-Aug-02 5:14
Anonymous4-Aug-02 5:14 
GeneralRe: SetFont Pin
valikac4-Aug-02 6:23
valikac4-Aug-02 6:23 
GeneralRe: SetFont Pin
Michael Dunn4-Aug-02 7:24
sitebuilderMichael Dunn4-Aug-02 7:24 
Generalsimple question in Vc Pin
glinda4-Aug-02 3:24
glinda4-Aug-02 3:24 
GeneralRe: simple question in Vc Pin
jmkhael4-Aug-02 10:16
jmkhael4-Aug-02 10:16 
Generalframeless documents and saving custom documents Pin
Chi Ling4-Aug-02 3:17
sussChi Ling4-Aug-02 3:17 
GeneralSending and receiving files trought CAsyncSocket derived class Pin
fdmanana4-Aug-02 2:28
fdmanana4-Aug-02 2:28 
Hi.I'm writing a dialog based aplication with support for sockets.I created my own derived class from CAsyncSocket.Whenever a client sends the string "cat <file>" to the server (where file is an ascii text file), the server responds sending the contents of the specified file to the client.The problem is that, most of the times, the server just sends about half of the contents of the file to the server.Here is the code I created to do this :

//on the server side:
//loop to read the contents of the file, f is a CFile object
//nbytes an UINT variable
//PacketSend(..) is my function to send the buffer to the client
while ( (nbytes = f.Read(buf,512)) )
PacketSend(buf,nbytes);
f.Close();

//PacketSend(..) function
void CConversarDlg::PacketSend(void *buffer,const int &length)
{
int total = sizeof(int) + length;
int sent;
int bufpos = 0;
BYTE *buf = new BYTE[sizeof(int) + length];

memcpy(buf,&length,sizeof(int));
memcpy((void *) (buf+sizeof(int)),buffer,length);
do
{
sent = ClientSocket->Send(buf+bufpos,total);
if ( sent == SOCKET_ERROR ) break;
total -= sent;
bufpos += sent;
if ( total > 0 ) Sleep(20);
} while ( total > 0 );
delete [] buf;
}

//on the client side:
//I call the funtion ReceivePacket on the overridable CAsyncSocket::OnReceive(int)

//PacketReceive(..) function
void CXploreDlg::PacketReceive(unsigned char **buffer)
{
unsigned char *buf;
int length;
int recv;
int bufpos = 0;
//clientsocket is an object of the derived CAsyncSocket Class I created
recv = clientsocket.Receive(&length,sizeof(int));
if ( recv != sizeof(int) || recv == SOCKET_ERROR ) return;
buf = new unsigned char[length + 1]; //+1 for the NULL character

do
{
recv = clientsocket.Receive(buf+bufpos,length);
if ( recv == SOCKET_ERROR ) break;
length -= recv;
bufpos += recv;
if ( length > 0 ) Sleep(20);
} while ( length > 0 );
*(buf + bufpos) = NULL;
*buffer = buf;
}

On the begining of each packet, I use 4 bytes (int value) for the client aplication to know the length of the packet,the rest is the contents of the ascii file specified....
I'm new to sockets, so I would apreciate a lot a little help...
I'm also trying to write code for downloading and uploading files, but i got exactly the same problem I mencioned before....
Thanks. Wink | ;)
Portugal.



Filipe David Manana
GeneralRe: Sending and receiving files trought CAsyncSocket derived class Pin
Imran Farooqui4-Aug-02 3:04
Imran Farooqui4-Aug-02 3:04 
GeneralRe: Sending and receiving files trought CAsyncSocket derived class Pin
Masaaki Onishi4-Aug-02 7:18
Masaaki Onishi4-Aug-02 7:18 
QuestionCRDBMS??? Pin
alex.barylski4-Aug-02 2:18
alex.barylski4-Aug-02 2:18 
AnswerRe: CRDBMS??? Pin
Pavel Klocek4-Aug-02 6:54
Pavel Klocek4-Aug-02 6:54 
QuestionATL Problems ? Pin
Leesen3-Aug-02 22:56
Leesen3-Aug-02 22:56 
AnswerRe: ATL Problems ? Pin
Christian Graus3-Aug-02 23:07
protectorChristian Graus3-Aug-02 23:07 
GeneralRe: ATL Problems ? Pin
Leesen3-Aug-02 23:39
Leesen3-Aug-02 23:39 
AnswerRe: ATL Problems ? Pin
Michael P Butler4-Aug-02 2:40
Michael P Butler4-Aug-02 2:40 
AnswerRe: ATL Problems ? Pin
Philippe Mori5-Aug-02 8:15
Philippe Mori5-Aug-02 8:15 
GeneralADO in console App Pin
Virtual Destructor3-Aug-02 22:02
Virtual Destructor3-Aug-02 22:02 
GeneralRe: ADO in console App Pin
Michael P Butler3-Aug-02 23:46
Michael P Butler3-Aug-02 23:46 
QuestionHow can i know if the desktop windows Z order has been changed Pin
adara3-Aug-02 20:34
adara3-Aug-02 20:34 
GeneralCommand Line arguments Pin
CaLvin Tan3-Aug-02 19:28
CaLvin Tan3-Aug-02 19:28 
GeneralRe: Command Line arguments Pin
Michael Dunn3-Aug-02 20:13
sitebuilderMichael Dunn3-Aug-02 20:13 
QuestionHow to draw shadow of sphere and line Pin
dark-gura3-Aug-02 18:52
dark-gura3-Aug-02 18:52 
Question(Cloning) How do I enable "Multiple Instance" in a C++ app? Pin
BaByBoI3-Aug-02 18:51
sussBaByBoI3-Aug-02 18:51 
AnswerRe: (Cloning) How do I enable "Multiple Instance" in a C++ app? Pin
Ravi Bhavnani3-Aug-02 20:56
professionalRavi Bhavnani3-Aug-02 20:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.