title: Windows Socket Programming in C
body: <p>I am taking a networking class where the Professor is literally reading the book to the class. Needless to say I have no Idea what I am doing. Our semester project is to copy code from our text book and make a client-server network. Literally copying the code from teh book with no modifications.</p>
  
  <p>The book had mistakes in the code (missing semicolons, extra paranthesis) but I managed to at least compile the code. However, I run into a bunch of link errors.</p>
  
  <p>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</p>
  
  <p>i looked up the error code and I think the code is trying to link to definitions that are not existent in the header files. I have a tough time fixing LNK errors vs Syntax errors. But like I said I have no idea how to go about fixing this. I am sending the code for the server side, I ran into the same errors on the client side.</p>
  
  <pre><code>include &lt;stdio.h&gt;
  include &lt;string.h&gt;
  include &lt;WinSock2.h&gt;
  include &lt;WinSock.h&gt;
  include &lt;stdint.h&gt;
  include &lt;time.h&gt;
  
  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(&amp;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) &lt;0 ))
  {
     perror("Error: Socket Failed!");
      exit(1);
  }
  
  //bind socket to local address and port
  if((bind(s,(struct sockaddr*)&amp;servAddr, sizeof(servAddr))&lt;0))
  {
      perror("Error:bind failed!");
      exit(1);
  }
  
  for(;;)
  {
  len = recvfrom(s,buffer, sizeof(buffer),0,(struct sockaddr*)&amp;clntAddr, &amp;clntAddrLen);
  
      //send string
      sendto(s, buffer, len, 0, (struct sockaddr*)&amp;clntAddr, sizeof(clntAddr));
  }
  
  }
  </code></pre>
  
  <p>Any tips, links to useful info, or advice would be appreciated. I tried reading the text book but I am completely lost. Also, this is the only code related assignment we have done all semester. Everything else has been collecting packets using a packet sniffer. Literally came into class and said copy and run code on page X.</p>