UDP Client-Server Communication for Translating “New Generation English” to Formal English

 

Experiment 

UDP Client-Server Communication for Translating “New Generation English” to Formal English


Aim

To design and implement a UDP client-server program where the client sends a sentence with abbreviations, and the server translates it into formal English.


Objective

  • To understand UDP-based communication
  • To implement string processing at the server side
  • To perform real-time translation using predefined mappings

Theory

🌐 UDP Communication

UDP is a connectionless protocol:

  • No connection establishment
  • Faster communication
  • Uses sendto() and recvfrom()

🧠 Concept Used

  • Client sends a sentence with abbreviations
  • Server replaces abbreviations using a predefined dictionary
  • Translated sentence is sent back

📘 Abbreviation Mapping

AbbreviationMeaning
tbhto be honest
igI guess
tbfto be fair
atmat the moment
irlin real life
lollaughing out loud
asapas soon as possible
omgoh my God
ttyltalk to you later
idkI don’t know
nvmnever mind
idc                    I don't care

Algorithm

Client

  1. Create UDP socket
  2. Input sentence from user
  3. Send sentence to server
  4. Receive translated sentence
  5. Display result

Server

  1. Create UDP socket
  2. Bind to port
  3. Receive sentence from client
  4. Replace abbreviations with full forms
  5. Send translated sentence back

💻 Program


🔹 Server Program (UDP in C)

#include <stdio.h> #include <string.h> #include <arpa/inet.h> #include <unistd.h> #define PORT 12345 void translate(char *str) { struct { char *abbr, *full; } dict[] = { {"tbh", "to be honest"}, {"ig", "I guess"}, {"tbf", "to be fair"}, {"atm", "at the moment"}, {"irl", "in real life"}, {"lol", "laughing out loud"}, {"asap", "as soon as possible"}, {"omg", "oh my God"}, {"ttyl", "talk to you later"}, {"idk", "I don't know"}, {"nvm", "never mind"},
        {"idc", "I don't care"} }; char result[1024] = ""; char temp[100]; int i = 0, j; while (sscanf(str + i, "%s", temp) == 1) { int found = 0; for (j = 0; j < 12; j++) { if (strcmp(temp, dict[j].abbr) == 0) { strcat(result, dict[j].full); found = 1; break; } } if (!found) { strcat(result, temp); } strcat(result, " "); i += strlen(temp) + 1; } strcpy(str, result); } int main() { int sockfd; char buffer[1024]; struct sockaddr_in server_addr, client_addr; socklen_t len; sockfd = socket(AF_INET, SOCK_DGRAM, 0); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = INADDR_ANY; server_addr.sin_port = htons(PORT); bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)); printf("UDP Server running...\n"); len = sizeof(client_addr); recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr *)&client_addr, &len); printf("Received: %s\n", buffer); translate(buffer); sendto(sockfd, buffer, strlen(buffer)+1, 0, (struct sockaddr *)&client_addr, len); close(sockfd); return 0; }

🔹 Client Program (UDP in C)

#include <stdio.h> #include <string.h> #include <arpa/inet.h> #include <unistd.h> #define PORT 12345 int main() { int sockfd; char buffer[1024]; struct sockaddr_in server_addr; socklen_t len; sockfd = socket(AF_INET, SOCK_DGRAM, 0); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(PORT); server_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); printf("Enter sentence:\n"); fgets(buffer, sizeof(buffer), stdin); sendto(sockfd, buffer, strlen(buffer)+1, 0, (struct sockaddr *)&server_addr, sizeof(server_addr)); len = sizeof(server_addr); recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr *)&server_addr, &len); printf("\nTranslated Sentence:\n%s\n", buffer); close(sockfd); return 0; }

▶️ Compilation and Execution

gcc server.c -o server gcc client.c -o client

Run:

  • Terminal 1 → ./server
  • Terminal 2 → ./client

📌 Sample Output

Client Input

Really idc about this server atm but ig it works lol

Client Output

Translated Sentence: Really i dont care about this server at the moment but I guess it works laughing out loud

⚠️ Limitations

  • Only predefined abbreviations are translated
  • Case-sensitive (e.g., “LOL” not handled)
  • Punctuation handling is basic

Result

The UDP client-server program successfully translated informal English abbreviations into formal English and returned the result to the client

This experiment also demonstrates UDP-based communication and highlights how simple string processing can be integrated into network applications.

Comments

Popular posts from this blog

Networks Lab PCCSL507 Semester 5 KTU CS 2024 Scheme - Dr Binu V P

Analysis of HTTP Protocol using Wireshark

Study and Use of ifconfig Command