1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
int main(int argc, char** argv) {
//creating server
struct sockaddr_un serverAddress;
int serverSocket, clientSocket;
serverSocket = socket(AF_LOCAL, SOCK_STREAM, 0);
serverAddress.sun_family = AF_LOCAL;
strcpy(serverAddress.sun_path, "GameServer");
unlink("GameServer");
bind(serverSocket, (struct sockaddr *) &serverAddress, SUN_LEN(&serverAddress));
listen(serverSocket, 5);
//client socket
clientSocket = socket(PF_LOCAL, SOCK_STREAM, 0);
connect(clientSocket, (struct sockaddr *) &serverAddress, SUN_LEN(&serverAddress));
for(; ;)
{
clientSocket = accept(serverSocket, (sockaddr *) NULL, NULL);
Computer c;
c.arrangeShips();
c.saveInFile();
//code for communication between server and client.
shutdown(clientSocket, 2);
close(clientSocket);
}
return 0;
}
|