title: TCP server client using g++
body: <p>i just started networking and this is my first program server client TCP connection
  when i compiled them m getting error regarding struct</p>
  
  <pre><code>client.cpp: In function ‘int main()’:
  client.cpp:15:2: error: ‘sock_addr_in’ was not declared in this scope
  client.cpp:15:15: error: expected ‘;’ before ‘server_addr’
  client.cpp:18:1: error: ‘server_addr’ was not declared in this scope
  </code></pre>
  
  <p>server.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  using namespace std;
  
  int main()
  {
  struct in_addr addr;
  char msg[100];
  int conn_sock,comm_sock,n;
  struct sockaddr_in server_addr,client_addr;
  conn_sock=socket(AF_INET,SOCK_STREAM,0)
  server_addr.sin_family=AF_INET;
  server_addr.sin_port=htons(1234);
  server_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
  
  bind(conn_sock, (struct sockaddr *)&amp;server_addr,sizeof(server_addr));
  
  listen(conn_sock,10);
  comm_sock=accept(conn_sock, (struct sockaddr *)&amp;client_addr, (socklen_t *)&amp;client_addr);
  
  cout&lt;&lt;"n\n\nConnection established with client";
  n=read(comm_sock,msg,100);
  
  cout&lt;&lt;"\n\nReceived data from client is :\n"&lt;&lt;msg;
  
  close(comm_sock);
  close(conn_sock);
  return 0;
  }
  </code></pre>
  
  <p>client.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  
  using namespace std;
  
  int main(){
  
  char msg[100]="hello";
  int conn_sock;
  struct sock_addr_in server_addr;
  conn_sock=socket(AF_INET,SOCK_STREAM,0);
  
  server_addr.sin_family=AF_INET;
  server_addr.sin_port=htons(1234);
  server_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
  
  connect(conn_sock, (struct sockaddr *)&amp;server_addr, sizeof (server_addr));
  
  write(conn_sock,msg,strlen(msg));
  close(conn_sock);
  return 0;
  
  }
  </code></pre>
  
  <p>am getting errors in this program and i dont know whats wrong here =(
  plz can anyone guide me here?</p>