Socket Programming

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 27
Reputation: winky is an unknown quantity at this point 
Solved Threads: 0
winky's Avatar
winky winky is offline Offline
Light Poster

Socket Programming

 
0
  #1
Feb 11th, 2008
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.

  1. #include <winsock.h>
  2. #include <winsock2.h>
  3. #include <ws2tcpip.h>
  4.  
  5. int main()
  6. {
  7. int socketId = socket(AF_INET, SOCK_DGRAM, 0);
  8.  
  9. sockaddr_in serverAddr, clientAddr;
  10. sockaddr &serverAddrCast = (sockaddr &) serverAddr;
  11. sockaddr &clientAddrCast = (sockaddr &) clientAddr;
  12.  
  13. serverAddr.sin_family = AF_INET;
  14. serverAddr.sin_port = htons(serverPort);
  15. serverAddr.sin_addr.s_addr = INADDR_ANY;
  16.  
  17. bind(socketId, &serverAddrCast, sizeof(addr));
  18.  
  19. int size = sizeof(clientAddr);
  20. recvfrom(socketId, buffer, bufferSize, 0, clientAddrCast, &size);
  21.  
  22. sendto(socketId, buffer, bufferSize, 0, clientAddrCast, size);
  23.  
  24. close(socketId);
  25. }
  26.  
  27. int sendto(int sid, const void *bufferPtr, size_t bufferLength, int flag, struct sockaddr *addrPtr, socklen_t addrLength)
  28. {
  29. }
  30.  
  31. int recvfrom(int sid, void *bufferPtr, int bufferlength, int flag, sockaddr *addrPtr, int *addrLengthPtr)
  32. {
  33. }

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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,350
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Socket Programming

 
0
  #2
Feb 11th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 350
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 44
gerard4143's Avatar
gerard4143 gerard4143 is online now Online
Posting Whiz

Re: Socket Programming

 
0
  #3
Feb 11th, 2008
I seen something like this in linux socket programming. Try using a socklen_t pointer. The worst that can happen it won't work.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1
Reputation: fida hussain is an unknown quantity at this point 
Solved Threads: 0
fida hussain fida hussain is offline Offline
Newbie Poster

Re: Socket Programming

 
0
  #4
Feb 19th, 2008
Originally Posted by Ancient Dragon View Post
See this thread. Looks like you have to define socklen_t yourself.
i want to know how to use lan in c++.coding & header files of this project
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC