Provided an variety of unsorted positive integer, kind the provided array making use of the Outlet development.
A readable event will be delivered when a new connection is attempted and you may then call accept to get a socket for that connection. Alternatively, you can set the socket to deliver SIGIO when activity occurs on a socket; see socket(7) for details. If flags is 0, then accept4 is the same as accept.
Examples:
Compile these files usinggcccontrol (gcc client.chemical -o client and gcc server.chemical -o server). Run the plan using./serverand./client(Please note : First you should run server plan which will be waiting for customer's reaction and then client code).
In this program, customer will get the insight and deliver it to server and the machine will type the variety using the bubble sort.
#include lt;arpa/inet.hgt; #consist of lt;line.hgt; #include lt;unistd.hgt; // Driver program code
struct sockaddrin server; int amount10 = 5, 4, 3, 8, 9, 1, 2, 0, 6 , i, temp; // Create socket if (sock -1)
server.sinfamily = AFINET; if (connect(sock, ( struct sockaddr.)amp;machine, sizeof (server)) lt; 0) return 1; if (send out(sock, amp;number, 10. sizeof ( int ), 0) lt; 0) return 1; if (recv(sock, amp;serverreply, 10. sizeof ( int ), 0) lt; 0) return 0; for (i = 0; i lt; 10; i actually)
// close up the socket return 0; |
Notice :Save above file as customer.c
#include lt;arpa/inet.hgt; #consist of lt;thread.hgt; #consist of lt;unistd.hgt; void bubblesort( int , int ); // Motorist program code
struct sockaddrin machine, customer; socketdesc = socket(AFINET, SOCKSTREAM, 0); printf ( 'Could not create socket' ); places ( 'Outlet made' ); // Prepare the sockaddrin structure server.sinaddr.saddr = INADDRANY; if (join(socketdesc, ( struct sockaddr.)amp;server, sizeof (machine)) lt; 0) // print out the mistake message return 1; places ( 'situation carried out' ); // lsiten to the socket chemical = sizeof ( struct sockaddrin); // accept link from an incoming customer clientsock = accept(socketdesc, ( struct sockaddr.)amp;client, (socklent.)amp;chemical); if (clientsock lt; 0) return 1; while ((readsize = recv(clientsock, amp;message, 10. sizeof ( int ), 0)) gt; 0) bubblesort(message, 10); create(clientsock, amp;message, 10. sizeof ( int )); puts ( 'Client shut off' ); else if (readsize -1)
return 0; void bubblesort( int checklist, int d) int c, d, t; for (d = 0; chemical lt; (d - 1); d) if (listd gt; listd + 1) /. Swapping./ listd = listd + 1;
|
Take note :Save over file as server.chemical
Result:
Result:
Recommended Posts:
If you like GeeksforGeeks and would including to lead, you can also compose an post using contribute.geeksforgeeks.org or mail your write-up to [email protected]. Observe your post showing up on the GeeksforGeeks primary web page and assist additional Geeks.
Please Improve this content if you find anything incorrect by clicking on the 'Improve Post' button beneath.