source: network-game/common/Message.cpp@ 7511a2b

Last change on this file since 7511a2b was b07eeac, checked in by dportnoy <dmp1488@…>, 12 years ago

Players pick up flags when they get close to the flag objects, not the structres. When a flag is picked up, a REMOVE_OBJECT message is sent

  • Property mode set to 100644
File size: 808 bytes
Line 
1#include "Message.h"
2
3#include "Compiler.h"
4
5#if defined WINDOWS
6 #include <winsock2.h>
7 #include <WS2tcpip.h>
8#elif defined LINUX
9 #include <sys/socket.h>
10 #include <netinet/in.h>
11#endif
12
13#include <iostream>
14
15using namespace std;
16
17int sendMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest)
18{
19 int ret = sendto(sock, (char*)msg, sizeof(NETWORK_MSG), 0, (struct sockaddr *)dest, sizeof(struct sockaddr_in));
20
21 cout << "Send a message of type " << msg->type << endl;
22
23 return ret;
24}
25
26int receiveMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest)
27{
28 socklen_t socklen = sizeof(struct sockaddr_in);
29
30 // assume we don't care about the value of socklen
31 int ret = recvfrom(sock, (char*)msg, sizeof(NETWORK_MSG), 0, (struct sockaddr *)dest, &socklen);
32
33 return ret;
34}
Note: See TracBrowser for help on using the repository browser.