Track Tracer is a robust server-side application designed to manage passenger details for a transportation system. It leverages socket programming to communicate with clients—typically passengers booking train seats—ensuring a smooth and secure booking process.
- The server establishes a socket using
socket(AF_INET, SOCK_STREAM, 0)
for network communication. - Configures the server address (
struct sockaddr_in
) to bind to a specific IP address and port.
- Binds the socket to the specified IP address and port using
bind()
. - Listens for incoming connections using
listen()
.
- Upon receiving a connection request (
accept()
), the server establishes a connection with the client.
- Sends a welcome message (
server_message
) to the client upon connection. - Generates a random 4-digit OTP (
otp
) and sends it to the client for authentication.
- Prompts the client to enter a passkey.
- Compares the received passkey with the generated OTP.
- If the passkey matches, the server proceeds with collecting passenger details.
- Requests and receives the passenger's name, age, gender, date of travel, preferred train choice, and seat preference from the client.
- Receives the seat selection from the client and updates the seat matrix accordingly.
- Saves the collected passenger details along with the seat allocation in a file named
ticket.txt
.
- Offers the client the option to order food during the journey.
- Catches errors during socket operations and exits gracefully if any operation fails.
- Utilizes ANSI color escape codes (defined as macros) to enhance console output with colors for better readability.
-
Compile and run the server program on a machine connected to a network:
gcc server.c -o server
-
Run the compiled executable:
./server
-
Connect to the server using a compatible client-side application.
- Follow the prompts to enter necessary details and complete the booking process.
- Ensure the server is running and reachable from the client-side application.
- This program serves as a demonstration and requires further enhancements for robustness, security, and scalability in a real-world scenario.