Oh god, I was assuming scores were integers
[progcomp2012.git] / judge / manager / network.h
1 #include <sys/types.h>
2 #include <sys/socket.h>
3 #include <netinet/in.h>
4 #include <arpa/inet.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include <netdb.h>
10 #include <fcntl.h>
11 #include <errno.h>
12
13 #include <string>
14 #include "thread_util.h"
15
16 #ifndef NETWORK_H
17 #define NETWORK_H
18
19
20 class Network
21 {
22         public:
23                 Network(int newPort = 4560);
24                 virtual ~Network();
25                 bool Valid() const {return sfd != -1;}
26
27                 bool SendMessage(const char * print, ...); //Sends a formated message (NOTE: Prints a newline)
28                 bool SendMessage(const std::string & buffer) {return SendMessage(buffer.c_str());} //Sends a C++ string message
29                 bool GetMessage(std::string & buffer, double timeout=-1); //Retrieves a message, or waits for a timeout (if positive)
30
31         protected:
32                 int sfd;
33                 int port;
34                 FILE * file;
35                 
36 };
37
38 class Server : public Network
39 {
40         public:
41                 Server(int newPort = 4560);
42                 virtual ~Server() {}
43                 
44 };
45
46 class Client : public Network
47 {
48         public:
49                 Client(const char * server = "127.0.0.1", int newPort = 4560);
50                 virtual ~Client() {}
51 };
52
53 #endif //NETWORK_H

UCC git Repository :: git.ucc.asn.au