This is only my second instance at working with Sockets, I apologize in advance as my knowledge on the matter is clearly limited. Here's what I'm stuck on:
I have a Dialog box A. Dialog A has a button which opens Dialog Box B.
It contains two private variables:
receive->Create(_T("STATIC"), NULL, WS_CHILD | WS_VISIBLE,CRect(0, 0, 20, 20), t_pParent, 1234);
Create does this:
BOOL DialogB::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
return CDialog::Create(IDD, pParentWnd);
DialogB also contains all of the required IPs and port assignments required for the next step.
Is also has a button with runs the following code:
SockVersionRequested = MAKEWORD(1, 1);
if(WSAStartup(SockVersionRequested, &wsa_Data) == 0)
socket_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(socket_fd > 0)
sender_adr.sin_family = AF_INET;
sender_adr.sin_addr.s_addr = htonl(ip_sender);
sender_adr.sin_port = htons(port_sender);
receiver_adr.sin_family = AF_INET;
receiver_adr.sin_addr.s_addr = htonl(ip_receiver);
receiver_adr.sin_port = htons(port_receiver);
if(bind(socket_fd, (struct sockaddr *)&receiver_adr,sizeof(struct sockaddr_in)) == -1)
socket_fd = 0;
int recv_data = 0;
sz = sizeof(sockaddr_in);
recv_data = 0;
recv_data = recvfrom(socket_fd, data_buffer, 1024, 0, (struct sockaddr *)&sender_adr, &sz);
This code is being run on a laptop on a LAN network connected to an FPGA transmitting a gretting message broadcast once every 5 seconds.
In this case however it is unable to receive and gets stuck on recvfrom(),however I have also run the above code from DialogA and been able to properly receive the greeting message. This is how I know that the issue above comes from the fact that DialogB is not the main thread of the application.
Does anyone know how a way for me to properly receive the greeting from Dialog B?
I'll check back in a bit and see if more information on the issue is required.