Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Network Programming Lab — Free Notes & Tutorial

Free Network Programming Lab practicals for BTech CS — UDP and TCP socket programs in C, getsockname/getpeername, host and protocol lookup, IP address manipulation, telnet client, FTP client, web server, file transfer over sockets and advanced socket calls, with viva questions. 100% free.

This Network Programming Lab course is part of Siksha Sarovar and is 100% free for students in India — no sign-up required to read. It contains 11 structured lessons with examples, and pairs with our free online compiler and AI tutor.

What you will learn

  • UDP sockets
  • TCP sockets
  • Getsockname
  • Getpeername
  • Gethostbyname
  • Getaddrinfo
  • Inet_pton
  • Inet_ntop
  • Select
  • Telnet client
  • FTP PASV
  • HTTP server in C
  • Shutdown half-close
  • Getsockopt
  • Setsockopt
  • Readv
  • Writev

Course content (11 lessons)

  1. Lab 0: Environment Setup & Common Header Block — Run Everything Right Here Every experiment in this lab has a runnable version in the built-in compiler — click RUN CODE on any practical. Client–server pairs are combined into one…
  2. Experiment 1: Create Sockets for Sending and Receiving Data — Program Statement Create a pair of UDP sockets — a receiver bound to a well-known port and a sender that transmits a message and reads the reply. Running It 1. Terminal 1: gcc udp…
  3. Experiments 2 & 3: Obtain the Local & Remote Socket Address — Program Statement Connect a TCP socket to a remote host, then introspect both ends of the connection — getsockname for the local address, getpeername for the remote address. (The…
  4. Experiment 4: Information About Host, Network, Protocols & Domains — Program Statement Write a program that retrieves (a) host information, (b) network information, (c) the protocol table and (d) the local domain name. Theory Link Unit 3 "Name &…
  5. Experiment 5: Manipulate the IP Address — Program Statement Convert an IP address between string and binary forms, demonstrate byte ordering, and extract the network/host parts with a subnet mask. This experiment is pure…
  6. Experiment 6: A Telnet Client — Program Statement A minimal line-mode telnet: connect to any host and port, then relay stdin↔socket with select — this is the str cli function from Unit 2: Testing Test it against…
  7. Experiment 7: An FTP Client — Program Statement Demonstrate FTP's two-connection architecture: a control connection on port 21 carrying commands/replies, plus a separate data connection negotiated via PASV.…
  8. Experiment 8: A Web Server Using Sockets — Program Statement A minimal HTTP/1.0 server using the classic fork-per-client model: Testing Open http://localhost:8080 in a browser. Extension Parse the request path and serve…
  9. Experiment 9: File Access Using Sockets — Program Statement A file-transfer pair: the client asks for a filename, the server streams it back. The read-loop handles short counts — Unit 1's readn/writen lesson in practice.…
  10. Experiment 10: Advanced Socket System Calls — Program Statement One program demonstrating getsockopt / setsockopt , getpeername / getsockname , and scatter/gather I/O with readv / writev — run it against your echo server.…
  11. Viva Quick-Fire: Asked Nearly Every Year — Viva Quick-Fire (asked nearly every year) 1. Why htons() on the port — what happens without it on x86? (U1) 2. What is a value-result argument? Name three calls that use one. (U1)…

Lab 0: Environment Setup & Common Header Block

Run Everything Right Here

Every experiment in this lab has a runnable version in the built-in compiler — click RUN CODE on any practical. Client–server pairs are combined into one program with fork(): the child process plays the server, the parent plays the client, talking over loopback (127.0.0.1) exactly as they would across two terminals.

Compiler Info

PropertyValue
CompilerGCC (latest)
StandardC11
BackendWandbox Cloud (Linux sandbox)
SocketsBSD sockets API + fork() + loopback supported

Lab Setup (for your own machine)

For the real lab record, use any Linux box or WSL (Windows Subsystem for Linux) on Windows:

sudo apt install build-essential

Compile with gcc prog.c -o prog; for client–server experiments run the server and client in two separate terminals.

Common Header Block

Every program in this lab starts with the same include set — write it once at the top of your record:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

How This Lab Maps to the Theory Course

ExperimentTheory unit it demonstrates
1 — Sockets for send/receiveUnit 1 Elementary TCP Sockets + Unit 2 Elementary UDP Sockets
2 & 3 — Local & remote socket addressUnit 1 Socket Address Structures (value-result arguments)
4 — Host / network / protocol / domain infoUnit 3 Name & Address Conversions
5 — IP address manipulationUnit 1 Byte Ordering + Unit 3 Broadcasting
6 — Telnet clientUnit 2 I/O Multiplexing (select) + Unit 4 Remote Login
7 — FTP clientUnit 1 Multiple connections per application
8 — Web serverUnit 1 Concurrent Servers
9 — File access via socketsUnit 2 shutdown vs close (half-close)
10 — Advanced socket callsUnit 2 Socket Options & Advanced I/O
Tip: after each experiment, note in your record WHICH theory section it demonstrates — examiners reward the connection, and the viva questions are drawn from exactly those sections.

Experiment 1: Create Sockets for Sending and Receiving Data

Program Statement

Create a pair of UDP sockets — a receiver bound to a well-known port and a sender that transmits a message and reads the reply.

/* udp_recv.c — receiver */
int main(void) {
    int fd = socket(AF_INET, SOCK_DGRAM, 0);
    struct sockaddr_in addr = {0}, cli; socklen_t len = sizeof(cli);
    addr.sin_family = AF_INET; addr.sin_port = htons(9877);
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    bind(fd, (struct sockaddr *)&addr, sizeof(addr));
    char buf[1024];
    int n = recvfrom(fd, buf, sizeof(buf)-1, 0, (struct sockaddr *)&cli, &len);
    buf[n] = '\0';
    printf("received: %s\n", buf);
    sendto(fd, "got it!", 7, 0, (struct sockaddr *)&cli, len);
    close(fd); return 0;
}

/* udp_send.c — sender */
int main(void) {
    int fd = socket(AF_INET, SOCK_DGRAM, 0);
    struct sockaddr_in srv = {0};
    srv.sin_family = AF_INET; srv.sin_port = htons(9877);
    inet_pton(AF_INET, "127.0.0.1", &srv.sin_addr);
    sendto(fd, "hello sockets", 13, 0, (struct sockaddr *)&srv, sizeof(srv));
    char buf[1024];
    int n = recv(fd, buf, sizeof(buf)-1, 0);          /* reply */
    buf[n] = '\0'; printf("server says: %s\n", buf);
    close(fd); return 0;
}

Running It

  1. Terminal 1: gcc udp_recv.c -o udp_recv && ./udp_recv
  2. Terminal 2: gcc udp_send.c -o udp_send && ./udp_send

Theory Link

Unit 1 "Elementary TCP Sockets" + Unit 2 "Elementary UDP Sockets". Note in your record: the receiver must bind to a known port; the sender's port is assigned implicitly (ephemeral) on the first sendto.

Frequently asked questions

Is the Network Programming Lab course really free?

Yes. The entire Network Programming Lab course on Siksha Sarovar is free to read with no account required. You can optionally sign in with Google to save your progress.

Do I get a certificate for Network Programming Lab?

Yes — finish the lessons and pass the quiz to earn a free, verifiable certificate you can share on LinkedIn or with recruiters.

Can I run code while learning?

Yes. The built-in online compiler runs C, C++, Python, Java, PHP, JavaScript, C# and SQL directly in your browser — no installation needed.