Receive messages in dialog based application through socket
-
I am using following code to send message to remote machine through sockets, I am calling mentioned code when a button of MFC dialog based app is clicked and it is working fine. But I don't know how to receive messages from remote machine through sockets. Can anyone please guide me how to receive messages in dialog based application through socket?
WSADATA w; //Winsock startup info SOCKADDR_IN target; //Information about host int error = WSAStartup (0x0202, &w); // Fill in WSA info if (error) return 0; m_sckt = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); // Create socket if (m_sckt == INVALID_SOCKET) { return 0; } target.sin_family = AF_INET; // address family Internet target.sin_port = htons (PortNo); // set server’s port number target.sin_addr.s_addr = hostname; // set server’s IP //Try connecting... if (connect(m_sckt, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR) //Try binding { // error return 0; } send(m_sckt, "Test", 5, 0);
Thanks, Mushq