This repository was archived by the owner on Jun 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsfmlsocket.cpp
More file actions
59 lines (47 loc) · 1.56 KB
/
sfmlsocket.cpp
File metadata and controls
59 lines (47 loc) · 1.56 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdlib.h>
#include <string.h>
#include <SFML/Network/IpAddress.hpp>
#include <SFML/Network/Packet.hpp>
#include <SFML/Network/UdpSocket.hpp>
#include "sfmlsocket-int.h"
struct sendRobotData_t {
unsigned short port;
sf::IpAddress * ipaddress;
sf::UdpSocket * serverSocket;
};
extern "C" struct sendRobotData_t *initSendRobotData(char *ipaddress,
unsigned short port)
{
sf::IpAddress * sfIP;
sf::UdpSocket * serverSocket;
struct sendRobotData_t *hrobotdata;
sfIP = new sf::IpAddress(ipaddress);
serverSocket = new sf::UdpSocket;
serverSocket->bind(port);
hrobotdata =
(struct sendRobotData_t *) malloc(sizeof(struct sendRobotData_t));
hrobotdata->ipaddress = sfIP;
hrobotdata->serverSocket = serverSocket;
hrobotdata->port = port;
return hrobotdata;
}
extern "C" void destroySendRobotData(struct sendRobotData_t *hrobotdata)
{
delete hrobotdata->serverSocket;
delete hrobotdata->ipaddress;
free(hrobotdata);
}
extern "C" int sendRobotData(struct sendRobotData_t *hrobotdata,
short distfromctr, unsigned int distfromtarget)
{
sf::Packet sendPacket;
sf::Socket::Status socketStatus;
sendPacket.clear();
sendPacket << distfromctr << distfromtarget; /* << (float)42; */
socketStatus =
hrobotdata->serverSocket->send(sendPacket, *hrobotdata->ipaddress,
hrobotdata->port);
if (socketStatus != sf::Socket::Done)
return -1;
return 0;
}