title: Sockets programming use c
body: <p>Socket programming is being implemented using c language.</p>
  <p>I want to proceed until accept and send and recv processes in different functions.</p>
  <p>For example
  We would like to implement socket programming data transfer by calling a function called send_data() from a function called socket_strat().</p>
  <p>Can you forward the data from the server socket created in socket_start() as a function of send_data as a variable?</p>
  <pre><code>    int socket_desc , client_sock , c , read_size;
      struct sockaddr_in server , client;
      char client_message[2000];
      
      socket_desc = socket(AF_INET , SOCK_STREAM , 0);
      if (socket_desc == -1)
      {
          printf(&quot;Could not create socket&quot;);
      }
      puts(&quot;Socket created&quot;);
  
      //Prepare the sockaddr_in structure
      server.sin_family = AF_INET;
      server.sin_addr.s_addr = INADDR_ANY;
      server.sin_port = htons( 8888 );
  
      //Bind
      if( bind(socket_desc,(struct sockaddr *)&amp;server , sizeof(server)) &lt; 0)
      {
          //print the error message
          perror(&quot;bind failed. Error&quot;);
          return 1;
      }
      puts(&quot;bind done&quot;);
  
      //Listen
      listen(socket_desc , 3);
  
      //Accept and incoming connection
      puts(&quot;Waiting for incoming connections...&quot;);
      c = sizeof(struct sockaddr_in);
  
      //accept connection from an incoming client
      client_sock = accept(socket_desc, (struct sockaddr *)&amp;client, (socklen_t*)&amp;c);
      if (client_sock &lt; 0)
      {
          perror(&quot;accept failed&quot;);
          return 1;
      }
      puts(&quot;Connection accepted&quot;);
  </code></pre>
  <p>This is the server socket creation process to be used in start_socket, and proceed with accept() to wait for the client's access.</p>
  <p>I want to call the send_data() function when the client is connected.</p>
  <p>**send_data()function not yet implemented (The function below.)</p>
  <pre><code>write(client_sock , msg , strlen(msg));
  </code></pre>
  <p>The reason I'm implementing it like this is because...</p>
  <p>This is because socket communication is required when a specific event occurs in a program that goes around the infinite loop.</p>
  <p>Therefore, if you insert the start_socket() function into the program that goes around the infinite loop,</p>
  <p>Communication is not possible normally because the socket is created and becomes infinite.</p>