| | |
Winsock - weird problem with shutdown( socket, SD_SEND )
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
First..Im very beginner with winsock and network programing..
Im doing a simple app that can act or as server or as client. What Im doing is that I open the app twice in the same computer, in one I choose server, and in the other client.
With the server part, everything is fine, but with the client, when I shutdown the socket for sending, shutdown returns SOCKET_ERROR, I cant figure out why, the most weird thing is that WSAGetLastError() returns 0(zero)! That doesnt make sense..
Also, what Im doing is that if an error occur, I close the socket and quit the app, but if I just ignore that shutdown error, everythig is fine..
It doesnt make sense, its like shutdown should not return any error..
Heres the client part of my code:
Im doing a simple app that can act or as server or as client. What Im doing is that I open the app twice in the same computer, in one I choose server, and in the other client.
With the server part, everything is fine, but with the client, when I shutdown the socket for sending, shutdown returns SOCKET_ERROR, I cant figure out why, the most weird thing is that WSAGetLastError() returns 0(zero)! That doesnt make sense..
Also, what Im doing is that if an error occur, I close the socket and quit the app, but if I just ignore that shutdown error, everythig is fine..
It doesnt make sense, its like shutdown should not return any error..
Heres the client part of my code:
C++ Syntax (Toggle Plain Text)
//send data: iResult = send( ConnectSocket, sendBuffer, (int)strlen(sendBuffer), 0 ); //return size of bytes sent if( iResult == SOCKET_ERROR ){ MessageBox( NULL, TEXT("send() failed"), TEXT(" winsock error"), MB ); closesocket( ConnectSocket ); return; } TCHAR buffer[100]; wsprintf( buffer, TEXT(" number of bytes sent: %i "), iResult ); TextOut( hdc, x, y, buffer, (int)strlen(buffer) ); y+=20; //--------------------------------------------------- //stop sending: iResult = shutdown( ConnectSocket, SD_SEND ); //it still receive! if( iResult = SOCKET_ERROR ){//*******HERES THE PROBLEM*************** iResult = WSAGetLastError();//****RETURNS ZERO????************ TextOut( hdc, x, y, TEXT(" shutdown() failed"), (int)strlen(TEXT(" shutdown() failed")) ); y+=20; //closesocket( ConnectSocket );//****COMMENTING THIS, WORKS FINE** //return; } //--------------------------------------------------- //receive data until server close connection: do{ iResult = recv( ConnectSocket, recvBuffer, 1000, 0 ); //return size of bytes received if( iResult > 0 ){ wsprintf( buffer, TEXT(" number of bytes received: %i "), iResult );//display bytes received TextOut( hdc, x, y, buffer, (int)strlen(buffer) ); y+=20; TextOut( hdc, x, y, recvBuffer, iResult ); //display data received y+=20; }else if( iResult == 0 ){ TextOut( hdc, x, y, TEXT("Connection Closed!"), (int)strlen(TEXT("Connection Closed!")) ); y+=40; }else{ TextOut( hdc, x, y, TEXT(" recv() failed"), (int)strlen(TEXT(" recv() failed")) ); y+=40; } }while( iResult > 0 ); //--------------------------------------------------- ReleaseDC( hmainwnd, hdc ); //stop receive and close socket: closesocket( ConnectSocket ); }
Last edited by Icebone1000; Sep 24th, 2009 at 3:55 pm.
•
•
•
•
The shutdown function disables sends or receives on a socket and you are using the ConnectSocket after the shutdown function to receive info.
The shutdown function is normally used before the close function so that you stop the stream flow before you close the socket.
•
•
Join Date: Sep 2009
Posts: 13
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
if( iResult = SOCKET_ERROR ){//*******HERES THE PROBLEM***************
C++ Syntax (Toggle Plain Text)
if( iResult == SOCKET_ERROR ){//*******HERES THE PROBLEM***************
![]() |
Similar Threads
- WinSock connect() problem. Client thinks it is connected even when Server is down (C++)
- Weird problem, one browser works, other one does not (Web Browsers)
- Weird problem with net connection (Networking Hardware Configuration)
- weird problem with my laptop (Troubleshooting Dead Machines)
- Winsock connection problem (Visual Basic 4 / 5 / 6)
- WinSock problems. (C++)
- XSLT weird problem... [urgent] (RSS, Web Services and SOAP)
- HELP!!! Weird problem... (C++)
- weird problem : Internet Explorer cannot load all geocities pages (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: plz help me with this Error!! it too simple but i cant find it!!
- Next Thread: very basic problem in c++
Views: 1121 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for network, shutdown(), win32, winsock
3g 3gs aliens apache api apic++ apple application army banking blades book broadband bt building c++ capacity client cloud community compile connect connection connectivity data data-center database delphi dialog dual engineering error fail failed glassfish government green growth hacking hmenu hotkey hsbc ibm icon infrastructure internet iphone jsp key keyboard kids management mobile mobile-apps modal network news o2 openssh passwords persuade php ping print protocol provider report richedit router safety savefile school security server servers seti shortcut shutdown() sms social sockets software space technology terrorism text uk valid visualstudio win32 win32api winsock wireless






