| | |
Socket Programming
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hey all,
I am currently learning about socket programming in my Networking class. Our teacher gave us an example of a server class for it, and while I was trying to build it I came across the error of it not being able to identify socklen_t. I am guessing that for some reason it is not contained in winsock.h or winsock2.h, so I was wondering if there might be a quick fix to this. Never had to add any libraries to my machine, so not really sure how to do that.
Also, if you guys could look at this and let me know if everything looks to be in at least the right place that would be awesome
Totally new to any client-server programming, so I am relatively lost.
Error C2061: syntax error: identifier 'socklen_t'
I am currently learning about socket programming in my Networking class. Our teacher gave us an example of a server class for it, and while I was trying to build it I came across the error of it not being able to identify socklen_t. I am guessing that for some reason it is not contained in winsock.h or winsock2.h, so I was wondering if there might be a quick fix to this. Never had to add any libraries to my machine, so not really sure how to do that.
Also, if you guys could look at this and let me know if everything looks to be in at least the right place that would be awesome
Totally new to any client-server programming, so I am relatively lost. C++ Syntax (Toggle Plain Text)
#include <winsock.h> #include <winsock2.h> #include <ws2tcpip.h> int main() { int socketId = socket(AF_INET, SOCK_DGRAM, 0); sockaddr_in serverAddr, clientAddr; sockaddr &serverAddrCast = (sockaddr &) serverAddr; sockaddr &clientAddrCast = (sockaddr &) clientAddr; serverAddr.sin_family = AF_INET; serverAddr.sin_port = htons(serverPort); serverAddr.sin_addr.s_addr = INADDR_ANY; bind(socketId, &serverAddrCast, sizeof(addr)); int size = sizeof(clientAddr); recvfrom(socketId, buffer, bufferSize, 0, clientAddrCast, &size); sendto(socketId, buffer, bufferSize, 0, clientAddrCast, size); close(socketId); } int sendto(int sid, const void *bufferPtr, size_t bufferLength, int flag, struct sockaddr *addrPtr, socklen_t addrLength) { } int recvfrom(int sid, void *bufferPtr, int bufferlength, int flag, sockaddr *addrPtr, int *addrLengthPtr) { }
Error C2061: syntax error: identifier 'socklen_t'
"First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack."
-George Carrette
-George Carrette
See this thread. Looks like you have to define socklen_t yourself.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 0
i want to know how to use lan in c++.coding & header files of this project
![]() |
Similar Threads
- Socket Programming... (C#)
- About socket programming in php (PHP)
- Socket Programming (ASP.NET)
- C++ socket programming (C++)
- Socket (C++)
- Socket programming + porting Unix to Win32 (C)
Other Threads in the C++ Forum
- Previous Thread: Creating a loop? Need some guidance!
- Next Thread: Making two infinate loops inside the other?
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






