// This will not run (properly) under MSDOS // Header files #include #include #include #include #include // Server application using sockets int main (int argc, char * argv[]) { // Determine the program parameter if (argc != 2) { cerr << "Usage: isprime " << endl; return 1; } int number = atoi(argv[1]); // Create the socket int sid = socket(AF_UNIX, SOCK_STREAM, 0); // Connect struct sockaddr sa; sa.sa_family = AF_UNIX; strcpy(sa.sa_data, "prime"); if (connect(sid, &sa, sizeof(sa.sa_family) + sizeof("prime")) == 0) cout << "Client: connected to server " << endl; else { cerr << "No available server" << endl; return 1; } // Send the request cout << "Client: sending, isprime(" << number << ") ?" << endl; send(sid, &number, sizeof(number), 0); // Receive the result int prime; recv(sid, &prime, sizeof(prime), 0); cout << "Client: received, isprime(" << number << ") = " << (prime ? "true" : "false") << endl; // Shut down the connection and close the socket cout << "Client: shuting down the connection " << sa.sa_data << endl; shutdown(sid, 2); close(sid); return 0; }