// JP opened flex table

Click to See Complete Forum and Search --> : Question about recv


michaeledooley
November 20th, 2002, 10: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();

michaeledooley
November 21st, 2002, 10:12 AM
Not that I think it makes much of a difference, but the Sleep above recv has been removed... same problem... Any thoughs??

Thanks,
Michael

Mouse_103
November 7th, 2006, 05:17 AM
stupid UDP.... I have same problem too.
can someone help?

humptydumpty
November 7th, 2006, 05:39 AM
As you guys Know that recv is a Blocking call. your Recv hangs due to Connection Close. if you maintain a log File and Enter your All Event in that you will notice that server side connection is close.so better if you put your recv in a thread and use some time synchronization on that.i mean to say give a timeout to thread so if your thread will hang application Will automatically detect it and respond to your next task.

Thanx

Marc G
November 7th, 2006, 07:29 AM
[ moved thread ]

MikeAThon
November 7th, 2006, 10:07 AM
This thread is four years old. Start a new one.

Mike

//JP added flex table