Windows Socket Programming in C -


i taking networking class professor literally reading book class. needless have no idea doing. our semester project copy code our text book , make client-server network. literally copying code teh book no modifications.

the book had mistakes in code (missing semicolons, paranthesis) managed @ least compile code. however, run bunch of link errors.

example: error 1 error lnk2019: unresolved external symbol impsendto@24 referenced in function _main c:\users\documents\visual studio 2010\projects\client_server\client_server\client_server\server.obj client_server

i looked error code , think code trying link definitions not existent in header files. have tough time fixing lnk errors vs syntax errors. said have no idea how go fixing this. sending code server side, ran same errors on client side.

include <stdio.h> include <string.h> include <winsock2.h> include <winsock.h> include <stdint.h> include <time.h>  int main(void) {  int s;       int len; char  buffer[256];   struct sockaddr_in servaddr;  struct sockaddr_in clntaddr;   int clntaddrlen; //length of client socket addre  //build local (server) socket add  memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = af_inet; servaddr.sin_port = htons(21); servaddr.sin_addr.s_addr = htonl(inaddr_any);     //create socket if((s=socket(pf_inet, sock_dgram, 0) <0 )) {    perror("error: socket failed!");     exit(1); }  //bind socket local address , port if((bind(s,(struct sockaddr*)&servaddr, sizeof(servaddr))<0)) {     perror("error:bind failed!");     exit(1); }  for(;;) { len = recvfrom(s,buffer, sizeof(buffer),0,(struct sockaddr*)&clntaddr, &clntaddrlen);      //send string     sendto(s, buffer, len, 0, (struct sockaddr*)&clntaddr, sizeof(clntaddr)); }  } 

any tips, links useful info, or advice appreciated. tried reading text book lost. also, code related assignment have done semester. else has been collecting packets using packet sniffer. literally came class , said copy , run code on page x.

you need link library ws2_32.lib use winsock. must call wsastartup before using other winsock functions (this isn't causing current error, cause problems once fix missing library issue).


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -