Last change
on this file since e084950 was e084950, checked in by dportnoy <dmp1488@…>, 12 years ago |
Converted the server to use sendMessage and receiveMessage and it now asks the user to guess a number between 1 and 1000
|
-
Property mode
set to
100644
|
File size:
626 bytes
|
Rev | Line | |
---|
[d87708d] | 1 | #include "message.h"
|
---|
| 2 |
|
---|
| 3 | #include "compiler.h"
|
---|
| 4 |
|
---|
[e084950] | 5 | #if defined WINDOWS
|
---|
[d87708d] | 6 | #include <winsock2.h>
|
---|
[e084950] | 7 | #elif defined LINUX
|
---|
| 8 | #include <sys/socket.h>
|
---|
| 9 | #include <netinet/in.h>
|
---|
[d87708d] | 10 | #endif
|
---|
| 11 |
|
---|
| 12 | int sendMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest)
|
---|
| 13 | {
|
---|
| 14 | return sendto(sock, (char*)msg, sizeof(NETWORK_MSG), 0, (struct sockaddr *)dest, sizeof(struct sockaddr_in));
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | int receiveMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest)
|
---|
| 18 | {
|
---|
[e084950] | 19 | socklen_t socklen = sizeof(struct sockaddr_in);
|
---|
[d87708d] | 20 |
|
---|
| 21 | // assume we don't care about the value of socklen
|
---|
| 22 | return recvfrom(sock, (char*)msg, sizeof(NETWORK_MSG), 0, (struct sockaddr *)dest, &socklen);
|
---|
[e084950] | 23 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.