Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UDP Client - Release version not working in VS 2005 only

Status
Not open for further replies.

JB009

Programmer
Mar 29, 2006
7
0
0
US
Hi, I have a simple UDP client/server program that that sends (server) a text string and receives (client) that text string to display on the dialog box. This is a MFC C++ program and I have it working properly in Visual Studio 6.0, Visual Studio 2003 in both the debug and release versions. I am trying to get the same code executing on Visual Studio 2005 and unfortunately the UDP client only seems to work in the debug mode, and not in release mode. Here is exactly what happens if I try to run the UDP client executable in release mode: When the UDP client receives a packet from the server, my read function gets called, and it receives the data and my dialog exits, just exits.... I commented out my OnOK(), OnCancel() functions to see if they were being called after it receives the packet, but not the case. It gets through my entire read function and just exits, it's like it's not coming back to the dialog....

Again, please keep in mind I have the same exact code working in VS 6, VS 2003 in both debug and release mode, but I have to have this in VS 2005

I've included some code and if anyone can shed any light on what may be happening, I would greatly apperciate it.

By the way, I've tried setting the project properties under release mode to disable optimization, etc to see if that could be causing any problems and still no luck.....

Here is what I have in my implementation file for my UDP client application:

Code:
BEGIN_MESSAGE_MAP(CUDPClientDlg, CDialog)

ON_MESSAGE(WM_SOCKETREAD,(LRESULT(AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))readData)

END_MESSAGE_MAP()

BOOL CUDPClientDlg::OnInitDialog() {

// Socket Initialization

WSADATA data;
if (WSAStartup(MAKEWORD(2,2), &data) != 0) return(0);

int ret;
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (!sock)
{
        WSACleanup();
        return(0);
}

saServer.sin_family = AF_INET;
saServer.sin_addr.s_addr = INADDR_ANY;
saServer.sin_port = htons(0x1983);
ret = bind(sock, (SOCKADDR *)&saServer, sizeof(SOCKADDR));

WSAAsyncSelect(sock, this->m_hWnd, WM_SOCKETREAD, FD_READ);

}

LRESULT CUDPClientDlg::readData()

{

char bufferTMP[4096];

memset(bufferTMP, '\0', sizeof(bufferTMP));

socklen_t fromaddrLen = sizeof(fromSockAddr); 

recvfrom(sock, bufferTMP, sizeof(bufferTMP)-1, 0, (struct sockaddr*)   
                                    &fromSockAddr, &fromaddrLen);

SetDlgItemText(IDC_EDIT1, bufferTMP);

return 1;

}

void CUDPClientDlg::OnExit() 
{

closesocket(sock); WSACleanup(); OnOK();

}
 
Are all 3 versions running on the same type of machine or is the VS2005 version running on a very much faster machine than the VS6 version? Just wondering if it is a timing problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top