Home > recvfrom error > recvfrom error 10022

Recvfrom Error 10022

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up recvfrom() returns error 10022 when passing socket handle to thread up vote 1 down vote favorite I'm working on UDP chat for programming classes. For now, I'm dealing with parallel in/out. So, I'm creating thread to receive messages from server: // in-thread DWORD WINAPI in_thread(void* param) { int n; // variable receivefrom returned char buff2[1000]; sockaddr_in client_addr; int client_addr_size = sizeof(client_addr); SOCKET my_sock; my_sock = (SOCKET)param; // casting from void* to SOCKET // reading server message while (1) { n = recvfrom(my_sock, buff2, sizeof(buff2) - 1, 0, (sockaddr*)&client_addr, &client_addr_size); // ...................... } ExitThread(0); } And socket handle goes from: hThread = CreateThread(NULL, NULL, &in_thread, (void*)sock, NULL, &ThreadId); But I am recieving: Error 10022: Invalid argument. (Returned by rercvfrom) Where could it have gone wrong? edit: If it goes without passing to CreateThread, it works fine. For example: SOCKET sock; // Opening socket sock=socket(AF_INET, SOCK_DGRAM, 0); int n; // variable receivefrom returned char buff2[1000]; sockaddr_in client_addr; int client_addr_size = sizeof(client_addr); n= recvfrom(sock,buff2,sizeof(buff2)-1,0, (sockaddr *) &client_addr, &client_addr_size); It works fine, socket works, no errors given, but when I pass it to createthread like in code in the question, error occures. Using VS10, winsock2 lib. c++ sockets udp winsock createthread share|improve this question edited Dec 9 '13 at 0:48 asked Dec 9 '13 at 0:24 user3081123 138110 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote 'my_sock', and therefore 'param' and 'sock', is not a valid socket handle. Something wrong with your socket creation code. share|improve this answer answered Dec 9 '13 at 0:36 EJP 198k17144251 If it goes without passing to CreateThread, it works fine, socket works, no error

Forum Visual C++ & C++ Programming Visual C++ Programming Socket Error 10022 If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register or Login before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 7 of 7 Thread: Socket Error 10022 Tweet Thread http://stackoverflow.com/questions/20461091/recvfrom-returns-error-10022-when-passing-socket-handle-to-thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode February 18th, 2009,12:28 AM #1 scorrpeio View Profile View Forum Posts Member Join Date Dec 2008 Posts 86 Socket Error 10022 Hi......... I wrote the following code to listen to UDP data sent at specified port by http://forums.codeguru.com/showthread.php?471111-Socket-Error-10022 any machine using any application.... I used dialog box application.... m_DataReceived is variable of Edit Control box m_PortNo is varible to get the port no. When the connectme button is clicked the following code executes.... Code: UpdateData( TRUE ); if( !m_PortNo ) { MessageBox( "Please enter the Port No & then click \"Connect Me\"" ); return; } WSADATA wsaData; SOCKET RecvSocket; sockaddr_in RecvAddr; int Port = 6791; char RecvBuf[1024]; int BufLen = 1024; sockaddr_in SenderAddr; int SenderAddrSize = sizeof(SenderAddr); char m_SocError[23]; // Initialize Winsock WSAStartup(MAKEWORD(2,2), &wsaData); // Create a receiver socket to receive datagrams RecvSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); // Bind the socket to any address and the specified port. RecvAddr.sin_family = AF_INET; RecvAddr.sin_port = htons(m_PortNo); RecvAddr.sin_addr.s_addr = inet_addr( "255.255.255.255" ); int BindCheck = bind(RecvSocket, (SOCKADDR *) &RecvAddr, sizeof(RecvAddr)); if( 0 != BindCheck ) { AfxMessageBox("SocketBind"); } if(recvfrom(RecvSocket,RecvBuf,BufLen,0,(SOCKADDR *)&SenderAddr,&SenderAddrSize)== SOCKET_ERROR) { MessageBox("ERROR"); } else { m_DataReceived = RecvBuf; UpdateData(FALSE); closesocket(RecvSocket); WSACleanup(); exit(1) ; } } However though binding is successful I get the Error 10022 : WSAEINVAL That means the parameter in the

3 Replies - 2400 Views - Last Post: 31 October 2013 - 03:24 PM Rate Topic: #1 Ambitious D.I.C Head Reputation: 5 Posts: http://www.dreamincode.net/forums/topic/332961-wsa-error-10022/ 133 Joined: 08-May 13 WSA error 10022? Posted 31 October 2013 - http://cboard.cprogramming.com/networking-device-communication/84476-wsagetlasterror-returns-10022-a.html 01:29 PM #include #include int main() { char temp[500]; WSAData wsa; WORD ver=MAKEWORD(2,1); WSAStartup(ver,&wsa); SOCKADDR_IN addr; addr.sin_addr.s_addr=inet_addr("212.187.99.221"); addr.sin_family=AF_INET; addr.sin_port=htons(8888); SOCKET UDPCon=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); connect(UDPCon,(SOCKADDR*)&addr,NULL); sendto(UDPCon,"SAMP.@~|a.p.r^.",16,NULL,(SOCKADDR*)&addr,NULL); recvfrom(UDPCon,temp,200,NULL,NULL,NULL); std::cout<

Programming Boards Networking/Device Communication WSAGetLastError() returns 10022 Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: WSAGetLastError() returns 10022 Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 10-22-2006 #1 hardi View Profile View Forum Posts Registered User Join Date Jan 2005 Location Estonia Posts 131 WSAGetLastError() returns 10022 Hi. I just started learning networking and I managed to make this code: Code: #include #include using namespace std; int RequestedVersion = 2; void DoStuff() { SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (hSocket == INVALID_SOCKET) { cout << "Unable to create a socket" << endl; return; } sockaddr_in sockAddr; sockAddr.sin_family = AF_INET; sockAddr.sin_port = htons(80); sockAddr.sin_addr.S_un.S_addr = inet_addr("72.14.221.104"); // Connect to the server if (connect(hSocket, (sockaddr*)(&sockAddr), sizeof(sockAddr))!=0) { // error handling code cout << "Connection failed!" << endl; } else { cout << "Socket is connected" << endl; } if (bind(hSocket, (sockaddr*)(&sockAddr), sizeof(sockAddr))!=0) { cout << "Binding failed (" << WSAGetLastError() << ")" << endl; } } int main() { WSADATA wsadata; if (WSAStartup(MAKEWORD(RequestedVersion, 0), &wsadata) == 0) { cout << "Startup was successful!" << endl; if (RequestedVersion >= wsadata.wVersion) { cout << "Version " << wsadata.wVersion << endl; } DoStuff(); system("pause"); if (WSACleanup()) { cout << "Cleanup failed!" << endl; } } else { cout << "Startup failed!" << endl; } } it gives the following output when run: Startup was successful! Version 2 Socket is connected Binding failed (10022) Press any key to continue . . . So

 

Related content

bad address error recvfrom

Bad Address Error Recvfrom table id toc tbody tr td div id toctitle Contents div ul li a href Recvfrom Error Codes a li li a href Sendto Errno a li li a href Recvfrom C a li ul td tr tbody table p here for a quick overview of the site Help relatedl Center Detailed answers to any questions you might recvfrom error have Meta Discuss the workings and policies of this site About recvfrom error Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads p h id Recvfrom Error Codes

error recvfrom bad address

Error Recvfrom Bad Address table id toc tbody tr td div id toctitle Contents div ul li a href Recvfrom Error a li li a href Recvfrom Error a li li a href Recvfrom Error Codes a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might relatedl have Meta Discuss the workings and policies of this site recvfrom bad file descriptor About Us Learn more about Stack Overflow the company Business Learn more p h id Recvfrom Error p about hiring developers or posting ads

error recvfrom

Error Recvfrom table id toc tbody tr td div id toctitle Contents div ul li a href Recvfrom Example a li li a href Recvfrom Udp a li li a href Recvfrom Struct a li ul td tr tbody table p socket SYNOPSIS tt include a href basedefs sys socket h html sys socket h a br br ssize t recvfrom int tt i socket i tt void restrict tt i buffer i tt size t tt i length i tt br int tt i flags i tt struct sockaddr restrict tt relatedl i address i tt br socklen t

recvfrom error code 10035

Recvfrom Error Code table id toc tbody tr td div id toctitle Contents div ul li a href Recvfrom Timeout a li li a href Wsastartup a li li a href Winsock Send a li ul td tr tbody table p here for a quick overview of the site Help relatedl Center Detailed answers to any questions you might windows error have Meta Discuss the workings and policies of this site About wsaewouldblock Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting socket error ads with us Stack Overflow Questions Jobs Documentation Tags

recvfrom error invalid argument

Recvfrom Error Invalid Argument p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies relatedl of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up recvfrom returns invalid argument when from is

recvfrom error code 10022

Recvfrom Error Code p here for a quick overview of the site relatedl Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up Error while listening on UDP socket up vote

recvfrom error 14

Recvfrom Error table id toc tbody tr td div id toctitle Contents div ul li a href Sendto Errno a li li a href C Recv Bad Address a li li a href Sendto C a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this relatedl site About Us Learn more about Stack Overflow the company Business p h id Sendto Errno p Learn more about hiring developers or posting ads with us Stack Overflow Questions

recvfrom error 10040

Recvfrom Error p here for a quick overview of the site Help Center Detailed answers to any questions relatedl you might have Meta Discuss the workings and policies wsaemsgsize of this site About Us Learn more about Stack Overflow the company Business winsock Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up How to easily solve the message too

recvfrom error 10054

Recvfrom Error p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the relatedl workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up Windows UDP sockets recvfrom fails with error up vote