michaeledooley
November 20th, 2002, 09:51 PM
I have a question about the recv function. I have a loop that sets up my socket, sends information across using the send function, and then receives using the recv command, this works fine for a while, but then it appears that it gets stuck in the recv function. Any ideas? Any help you maybe able to provide will me greatly appricated.
Thanks,
Michael
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
// Initialize WinSock and check the version
WSAStartup(wVersionRequested, &wsaData);
LPHOSTENT lpHostEntry;
//strcpy(temp,m_ip_address);
lpHostEntry = gethostbyname(Ip_Address);
if (lpHostEntry == NULL)
{
return false;
}
// Create a TCP/IP stream socket
SOCKET theSocket;
theSocket = socket(AF_INET, // Address family
SOCK_DGRAM, // Socket type
IPPROTO_UDP); // Protocol
if (theSocket == INVALID_SOCKET)
{
return false;
}
// Fill in the address structure
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
// ^ Server's address
saServer.sin_port = htons(27015); // Port number from command line
// connect to the server
int nRet;
nRet = connect(theSocket, // Socket
(LPSOCKADDR)&saServer, // Server address
sizeof(struct sockaddr));// Length of server address structure
if (nRet == SOCKET_ERROR)
{
closesocket(theSocket);
return false;
}
// Send data to the server
char szBuf[256];
/* FILL szBuf
THIS HAS BEEN REMOVED FOR THE POST HERE */
nRet = send(theSocket, // Connected socket
szBuf, // Data buffer
strlen(szBuf), // Length of data
0); // Flags
if (nRet == SOCKET_ERROR)
{
closesocket(theSocket);
return false;
}
// Wait for a reply
Sleep(500);
nRet = recv(theSocket, // Connected socket
buffer, // Receive buffer
2560, // Size of receive buffer
0); // Flags
if (nRet == SOCKET_ERROR)
{
closesocket(theSocket);
return false;
}
closesocket(theSocket);
// Release WinSock
WSACleanup();
Thanks,
Michael
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
// Initialize WinSock and check the version
WSAStartup(wVersionRequested, &wsaData);
LPHOSTENT lpHostEntry;
//strcpy(temp,m_ip_address);
lpHostEntry = gethostbyname(Ip_Address);
if (lpHostEntry == NULL)
{
return false;
}
// Create a TCP/IP stream socket
SOCKET theSocket;
theSocket = socket(AF_INET, // Address family
SOCK_DGRAM, // Socket type
IPPROTO_UDP); // Protocol
if (theSocket == INVALID_SOCKET)
{
return false;
}
// Fill in the address structure
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
// ^ Server's address
saServer.sin_port = htons(27015); // Port number from command line
// connect to the server
int nRet;
nRet = connect(theSocket, // Socket
(LPSOCKADDR)&saServer, // Server address
sizeof(struct sockaddr));// Length of server address structure
if (nRet == SOCKET_ERROR)
{
closesocket(theSocket);
return false;
}
// Send data to the server
char szBuf[256];
/* FILL szBuf
THIS HAS BEEN REMOVED FOR THE POST HERE */
nRet = send(theSocket, // Connected socket
szBuf, // Data buffer
strlen(szBuf), // Length of data
0); // Flags
if (nRet == SOCKET_ERROR)
{
closesocket(theSocket);
return false;
}
// Wait for a reply
Sleep(500);
nRet = recv(theSocket, // Connected socket
buffer, // Receive buffer
2560, // Size of receive buffer
0); // Flags
if (nRet == SOCKET_ERROR)
{
closesocket(theSocket);
return false;
}
closesocket(theSocket);
// Release WinSock
WSACleanup();