{"id":21665949,"url":"https://github.com/man0sh-r0y/socket-programming-in-c","last_synced_at":"2025-03-20T06:28:43.523Z","repository":{"id":241955767,"uuid":"808299130","full_name":"Man0sh-r0y/Socket-Programming-in-C","owner":"Man0sh-r0y","description":"TCP/UDP client-server programs use Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) to transport data between a client and a server. I have used the concept of Socket Programming in C Language. Check the README file to know more info.","archived":false,"fork":false,"pushed_at":"2024-05-31T19:16:41.000Z","size":879,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-25T08:09:40.558Z","etag":null,"topics":["c","client-server","socket-programming","tcp-socket","udp-socket"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Man0sh-r0y.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-30T19:26:20.000Z","updated_at":"2024-05-31T19:16:45.000Z","dependencies_parsed_at":"2024-05-30T22:37:14.506Z","dependency_job_id":"e865425d-cd55-453b-afb4-da1fc2416e67","html_url":"https://github.com/Man0sh-r0y/Socket-Programming-in-C","commit_stats":null,"previous_names":["man0sh-r0y/socket-programming","man0sh-r0y/socket-programming-in-c"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Man0sh-r0y%2FSocket-Programming-in-C","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Man0sh-r0y%2FSocket-Programming-in-C/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Man0sh-r0y%2FSocket-Programming-in-C/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Man0sh-r0y%2FSocket-Programming-in-C/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Man0sh-r0y","download_url":"https://codeload.github.com/Man0sh-r0y/Socket-Programming-in-C/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244563663,"owners_count":20472895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","client-server","socket-programming","tcp-socket","udp-socket"],"created_at":"2024-11-25T11:18:48.008Z","updated_at":"2025-03-20T06:28:43.495Z","avatar_url":"https://github.com/Man0sh-r0y.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Client and Server Program using both TCP and UDP\n\nA Client and Server Program using TCP ensures reliable, connection-oriented communication. The server listens on a specific port and waits for client requests, establishing a connection to exchange data with guaranteed delivery. Conversely, a UDP based program offers connectionless, faster communication, where the server receives and processes datagrams from clients without establishing a dedicated connection, making it suitable for applications where speed is prioritized over reliability. Both protocols serve distinct needs based on the application's requirements for data integrity and transmission speed.\n\n![TCP-UDP-Data-Communication](./assets/TCP_and_UDP_data_sending.png)\n\n## Installation\n\n### TCP Client Server Program\n\n* **Step 1**: Complie The Program\n  ```bash\n  gcc tcpServer.c -o tcpServer # after compiling tcpServer.c, It instructs the compiler to output the compiled executable with the name tcpServer.\n  gcc tcpClient.c -o tcpClient # after compiling tcpClient.c, It instructs the compiler to output the compiled executable with the name tcpClient.\n  ```\n* **Step 2**: Run the Program\n  ```bash\n  ./tcpServer\n  ./tcpClient # run it in another terminal window\n  ```\n\n### UDP Client Server Program\n\n* **Step 1**: Complie The Program\n\n  ```bash\n  gcc udpServer.c -o udpServer \n  gcc udpClient.c -o udpClient \n  ```\n* **Step 2**: Run the Program\n\n  ```bash\n  ./udpServer 5566 # send the port number through argument\n  ./udpClient 5566 # run it in another terminal window\n  ```\n\n## What is Socket Programming?\n\nSocket programming is a way to connect two nodes on a network to communicate with each other. It uses socket APIs to establish communication links between local and remote processes. Sockets are a combination of an IP address and software port number that allows communication between multiple processes.\n\n![socket-programming](./assets/Socket-Programming.png)\n\n## What is Socket?\n\n* A socket is effectively a type of file handle.\n* A file handle in C is a pointer to a file. It is a data structure that holds information about the file\n* You can read and write it (mostly) like any other file handle and have the data go to and come from the other end of the session.\n* The specific actions you're describing are for the server end of a socket.\n* A server establishes (binds to) a socket which can be used to accept incoming connections.\n* Upon acceptance, you get *another* socket for the established session so that the server can go back and listen on the original socket for more incoming connections.\n* A socket allows an application to \"plug in\" to the network and communicate with other applications that are also plugged in to the same network.\n* Information written to the socket by an application on one machine can be read by an application on a different machine, and vice versa.\n\n## TCP Client Server Diagram\n\n![tcp-client-server](./assets/tcp_server_client.png)\n\n## UDP Client Server Diagram\n\n![udp-client-server](./assets/udp_server-client.png)\n\n## TCP vs UDP\n\n| Basis                    | TCP                                               | UDP                                                    |\n| ------------------------ | ------------------------------------------------- | ------------------------------------------------------ |\n| Connection               | Connection Oriented                               | connectionless                                         |\n| Usage                    | High reliability, critical-less transmission time | fast, efficient, small queries, huge number of clients |\n| Ordering of data packets | rearranges packets in order                       | No inherent order                                      |\n| Reliability              | Yes                                               | No                                                     |\n| Streaming od Data        | Read as a Byte Stream                             | Sent and read individually                             |\n| Error Checking           | Error Checking and Recovery                       | Simply error checking, no error recovery               |\n| Acknowledgement          | Acknowledgement segments                          | No acknowledgment                                      |\n\n## TCP Client Server Program Result\n\n![tcp-client-server-program-result](./assets/TCP_Client_Server_OutPut.png)\n\n## UDP Client Server Program Result\n\n![udp-client-server-program](./assets/UDP_Client_Server_OutPut.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fman0sh-r0y%2Fsocket-programming-in-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fman0sh-r0y%2Fsocket-programming-in-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fman0sh-r0y%2Fsocket-programming-in-c/lists"}