RE: Socket TimeOut
From: Sundari. (Sundari._at_discussions.microsoft.com)
Date: 01/03/05
- Next message: Rail Jon Rogut: "Re: Checking path validity"
- Previous message: Neelesh K J Jain: "Re: Beep Sound while executing the application"
- In reply to: Wilbert: "Socket TimeOut"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 2 Jan 2005 23:17:02 -0800
Hi,
Check out setsockopts API. Using this API you should be able to specify a
timeout interval.
Regards
Sundari
"Wilbert" wrote:
> Hi! folks
>
> I have a issue with my sockets built in VC ++ 6.0 .
>
> I want to avoid that my socket server stay waiting indefinably by a client
> conexion, that after certain time send a message of timeout, but I can not
> handle a diference of time ( time end - time start) because I will get the
> "time end" until the socket server get a conexion.
>
> I am using two methods 'BeginserverSession' where I prepare the params to
> iniciate the socket session and the 'AcceptConnection'. I guess that the key
> is in the second method, but know I don't have idea of how handle this.
>
> I'll show you the code and I hope you can give an idea of how to handle this.
>
> BeginServerSession(LPTSTR pszIp, LPTSTR pszPort)
> {
>
> // Reset socket params
> m_TcpSocket = INVALID_SOCKET;
> memset( (void *) &m_sinTCP, 0, sizeof(m_sinTCP));;
>
> // Create the TCP socket
> m_TcpSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
>
> // Get the IP Address of the Local Computer
> GetPeerName(pszIp);
>
> if(m_TcpSocket == INVALID_SOCKET)
> return SOCKET_CREATE_ERROR;
> // Prepare port and ip
> //m_usPort = atoi(pszPort);
>
> m_usPort=700;
> strcpy(m_cIp, pszIp);
> m_sinTCP.sin_family = AF_INET;
> m_sinTCP.sin_port = htons(m_usPort);
> m_sinTCP.sin_addr.S_un.S_addr = inet_addr(m_cIp);
>
> if(bind(m_TcpSocket, (struct sockaddr *)&m_sinTCP, sizeof(m_sinTCP)) ==
> SOCKET_ERROR){
> CloseSocket();
> return SOCKET_BIND_ERROR;
> }
> if(listen(m_TcpSocket, SOMAXCONN) == SOCKET_ERROR){
> CloseSocket();
> return SOCKET_LISTEN_ERROR;
> }
> return SOCKET_NO_ERROR;
> }
>
> AcceptConnection(SOCKET& c_Socket, SOCKADDR& SinConnect, int& nErr){
> int len=sizeof(SinConnect);
> c_Socket=accept(m_TcpSocket, &SinConnect, &len);
> if(c_Socket == INVALID_SOCKET){
> nErr=WSAGetLastError ();
> return FALSE;
> }
> return TRUE;
> }
>
>
- Next message: Rail Jon Rogut: "Re: Checking path validity"
- Previous message: Neelesh K J Jain: "Re: Beep Sound while executing the application"
- In reply to: Wilbert: "Socket TimeOut"
- Messages sorted by: [ date ] [ thread ]