linux c sockets -
Good evening, I am a newbie using Linux sockets under the C programming language.
For now I am trying to communicate with a client to a server. Basically the thing that I'm stuck on accepts the server connection to the customer and after printing numbers Prints. Here is the source code for the server so far:
#include & lt; Sys / socket.h & gt; #include & lt; Netinet / in.h> # Include & lt; Arpa / inet.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Unistd.h & gt; # Include & lt; Errno.h & gt; #include & lt; String.h & gt; # Include & lt; Sys / types.h & gt; # Include & lt; Time.h> Int main (int argc, char * argv []) {int listenfd = 0, connfd = 0, n = 0; Struct sockaddr_in serv_addr; Four transmitted buff [1024], retook buff [1024]; Listenfd = socket (AF_INET, SOCK_STREAM, 0); Memos (& amp; serv_addr, '0', ss (serv_addr)); Memeset (posted buff, '0', size (sender buff)); Serv_addr.sin_family = AF_INET; Serv_addr.sin_addr.s_addr = htonl (INADDR_ANY); Serv_addr.sin_port = htons (5000); Tie (Schroeder, (Structured Socadar *) and all-ADRR, shaped (all-ADE); Listen (listenfd, 10); While (1) {printf ("loop at first time \ n"); Connfd = Accept (listenfd, (struct sockaddr *) NULL, NULL); While ((read n = (Schroidy, Recover Buff, Size (Recover Buff) -1)) gt; 0) {printf ("loop at the second time \ n"); Recover Buff [N] = 0; Footprops (recovery buff, standout); }}} I did not post the client code because I do not think it is relevant. I have created a server that sends something to the client and it works fine. But I am seriously confused about how I want the customer to accept input from the customer. Thank you in advance.
You have to change
connfd = accept (listenfd, (Structured) Soceder *) Faucet, Faucet); To do this
connfd = (read = (n = reading, listenfd, recvBuff, sizeof (recvBuff) -1) Accept (listenfd, (straight sockaddr *) NULL, NULL); Can accept connections only in the form of listening / html>
Comments
Post a Comment