Changeset 483 for Daodan/Flatline/src
- Timestamp:
- Nov 29, 2009, 9:20:43 AM (15 years ago)
- Location:
- Daodan/Flatline/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Daodan/Flatline/src/Flatline.c
r460 r483 13 13 bool FLrServer_Run() 14 14 { 15 return Net _Listen(27777, FLrListen_PacketCallback);15 return NetUDPServer_Listen(27777, FLrServer_PacketCallback); 16 16 } -
Daodan/Flatline/src/Flatline.h
r460 r483 41 41 typedef struct sockaddr sockaddr; 42 42 typedef struct sockaddr_in sockaddr_in; 43 typedef sockaddr_storage sockaddr_in6; 43 44 44 45 bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from)); 45 bool NetUDPServer_Send(sockaddr* address, char* data, int datalen) 46 bool NetUDPServer_Send(sockaddr* address, char* data, int datalen); 46 47 47 48 int NetUDPSocket_Create(uint16_t port); 48 bool NetUDPSocket_Send(int socket, int ip, uint16_t port,char* data, int datalen);49 bool NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen); 49 50 void NetUDPSocket_Close(int sock); 50 51 … … 66 67 67 68 68 bool FLr Listen_PacketCallback(char* data, int datalen, int from);69 bool FLr Listen_Run();69 bool FLrServer_PacketCallback(char* data, int datalen, int from); 70 bool FLrServer_Run(); -
Daodan/Flatline/src/Flatline_Net.c
r460 r483 84 84 } 85 85 86 bool NetUDPSocket_Send(int socket, sockaddr* address,char* data, int datalen)86 bool NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen) 87 87 { 88 uint32_t addr_size;88 int addr_size; 89 89 switch (address->sa_family) 90 90 { … … 95 95 addr_size = sizeof(sockaddr_in6); 96 96 break; 97 default: 98 addr_size = sizeof(sockaddr_storage); 97 99 } 98 100 return sendto(socket, data, datalen, 0, address, addr_size); … … 101 103 bool NetUDPSocket_Recieve(int socket, sockaddr_storage* address, char* data, uint16_t* datalen) 102 104 { 103 uint32_t msg_size = recvfrom(socket, data, 512, 0, address, sizeof(sockaddr_storage)); 105 int address_size = sizeof(sockaddr_storage); 106 uint32_t msg_size = recvfrom(socket, data, 512, 0, (sockaddr*)address, &address_size); 104 107 if (msg_size == 0) 105 108 return false; -
Daodan/Flatline/src/testclient.c
r457 r483 5 5 { 6 6 NetPlatform_Initalize(); 7 int sock = Net _CreateSocket(0);7 int sock = NetUDPSocket_Create(0); 8 8 puts("Sending 100 two byte packets . . ."); 9 10 sockaddr_in address = { .sin_family = AF_INET, .sin_port = htons(27777), .sin_addr.S_un.S_addr = inet_addr("192.168.0.100") }; 9 11 10 12 int i; 11 13 for (i = 0; i < 100; i ++) 12 14 { 13 if (Net _Send(sock, inet_addr("127.0.0.1"), 27777, "hi", 3))15 if (NetUDPSocket_Send(sock, (sockaddr*)&address, "hi", 2)) 14 16 putchar('*'); 15 17 else 16 18 putchar('x'); 17 19 } 18 Net _CloseSocket(sock);20 NetUDPSocket_Close(sock); 19 21 NetPlatform_Shutdown(); 20 22 return 0; -
Daodan/Flatline/src/testserver.c
r457 r483 4 4 { 5 5 NetPlatform_Initalize(); 6 FLr Listen_Run();6 FLrServer_Run(); 7 7 NetPlatform_Shutdown(); 8 8 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.