problem with ReceiveFrom() function
-
Hi all, I am working on TFTP server application. When A client is requested for a file, My OnReceive() function is called. In the OnReceive(),I am unable to get the data requested. I used the function like CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); CAsyncSocket::OnReceive(nErrorCode); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); } Here I am able to get the IPAddress and Port correctly. But Unable to get data in the buff variable.But Size value is not zero. So what could be the problem? Please help me.
Regards, Sunil Kumar
-
Hi all, I am working on TFTP server application. When A client is requested for a file, My OnReceive() function is called. In the OnReceive(),I am unable to get the data requested. I used the function like CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); CAsyncSocket::OnReceive(nErrorCode); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); } Here I am able to get the IPAddress and Port correctly. But Unable to get data in the buff variable.But Size value is not zero. So what could be the problem? Please help me.
Regards, Sunil Kumar
Make sure that the value returned by the function "ReceiveFrom" is a positive number less than 100. Remember that the buffer ( buff[100]) you used to receive the data is sitting in the stack and will go out of scope when the function returns.
-
Make sure that the value returned by the function "ReceiveFrom" is a positive number less than 100. Remember that the buffer ( buff[100]) you used to receive the data is sitting in the stack and will go out of scope when the function returns.
-
Hi all, I am working on TFTP server application. When A client is requested for a file, My OnReceive() function is called. In the OnReceive(),I am unable to get the data requested. I used the function like CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); CAsyncSocket::OnReceive(nErrorCode); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); } Here I am able to get the IPAddress and Port correctly. But Unable to get data in the buff variable.But Size value is not zero. So what could be the problem? Please help me.
Regards, Sunil Kumar
CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); CAsyncSocket::OnReceive(nErrorCode); } Just try this way.
-@SuDhIrKuMaR@-
-
CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); CAsyncSocket::OnReceive(nErrorCode); } Just try this way.
-@SuDhIrKuMaR@-
-
Thanks for the reply, but still there is no data in buff. I think atleast it must have the filename I am requesting from tftp client.!
Regards, Sunil Kumar
Why you are using ReciveFrom not Revice?
-@SuDhIrKuMaR@-
-
Why you are using ReciveFrom not Revice?
-@SuDhIrKuMaR@-
-
Hi all, I am working on TFTP server application. When A client is requested for a file, My OnReceive() function is called. In the OnReceive(),I am unable to get the data requested. I used the function like CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); CAsyncSocket::OnReceive(nErrorCode); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); } Here I am able to get the IPAddress and Port correctly. But Unable to get data in the buff variable.But Size value is not zero. So what could be the problem? Please help me.
Regards, Sunil Kumar
First, there's no need to call CAsyncSocket::OnReceive(). It does nothing. If Size is > 0, then you received a datagram. If the data you expect isn't in the datagram, you need to look at the sender to see why. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: