| 64 |
|
int client_sock = 0; |
| 65 |
|
sockaddr_in client_address; |
| 66 |
|
|
| 67 |
< |
int NetUDPSocket_Create(uint16_t port) |
| 67 |
> |
int NetUDPSocket_Create(uint16_t port, sockaddr_in* address) |
| 68 |
|
{ |
| 69 |
|
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
| 70 |
< |
sockaddr_in address; |
| 70 |
> |
|
| 71 |
|
unsigned long nonBlocking = 1; |
| 72 |
|
if (sock < 0) |
| 73 |
|
{ |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
|
| 79 |
< |
memset(&client_address, 0, sizeof(sockaddr_in)); |
| 80 |
< |
address.sin_family = AF_INET; |
| 81 |
< |
address.sin_addr.s_addr = htonl(INADDR_ANY); |
| 82 |
< |
address.sin_port = htons(port); |
| 79 |
> |
// memset(&client_address, 0, sizeof(sockaddr_in)); |
| 80 |
> |
address->sin_family = AF_INET; |
| 81 |
> |
address->sin_addr.s_addr = htonl(INADDR_ANY); |
| 82 |
> |
address->sin_port = htons(port); |
| 83 |
|
|
| 84 |
< |
if (bind(sock, (sockaddr*)&address, sizeof(sockaddr_in)) < 0) |
| 84 |
> |
if (bind(sock, (sockaddr*)address, sizeof(sockaddr_in)) < 0) |
| 85 |
|
{ |
| 86 |
|
DDrConsole_PrintF("could not bind port %d", port); |
| 87 |
|
return false; |
| 94 |
|
return false; |
| 95 |
|
} |
| 96 |
|
client_sock = sock; |
| 97 |
– |
client_address = address; |
| 97 |
|
return sock; |
| 98 |
|
} |
| 99 |
|
|
| 100 |
< |
int NetTCPSocket_Create(uint16_t port) |
| 100 |
> |
int NetTCPSocket_Create(uint16_t port, sockaddr_in* address) |
| 101 |
|
{ |
| 102 |
|
int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 104 |
– |
sockaddr_in address; |
| 105 |
– |
unsigned long nonBlocking = 1; |
| 103 |
|
|
| 104 |
+ |
unsigned long nonBlocking = 0; |
| 105 |
|
if (sock < 0) |
| 106 |
|
{ |
| 107 |
|
DDrConsole_PrintF("could not create socket"); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
|
| 112 |
< |
memset(&client_address, 0, sizeof(sockaddr_in)); |
| 113 |
< |
address.sin_family = AF_INET; |
| 114 |
< |
address.sin_addr.s_addr = htonl(INADDR_ANY); |
| 115 |
< |
address.sin_port = htons(port); |
| 116 |
< |
|
| 117 |
< |
if (bind(sock, (sockaddr*)&address, sizeof(sockaddr_in)) < 0) |
| 112 |
> |
// memset(&client_address, 0, sizeof(sockaddr_in)); |
| 113 |
> |
//address->sin_family = AF_INET; |
| 114 |
> |
//address->sin_addr.s_addr = INADDR_ANY; |
| 115 |
> |
//address->sin_port = htons(port); |
| 116 |
> |
/* |
| 117 |
> |
if (bind(sock, (sockaddr*)address, sizeof(sockaddr_in)) < 0) |
| 118 |
|
{ |
| 119 |
|
DDrConsole_PrintF("could not bind port %d", port); |
| 120 |
|
return false; |
| 121 |
|
} |
| 122 |
|
|
| 123 |
< |
|
| 123 |
> |
/* |
| 124 |
|
if (ioctlsocket(sock, FIONBIO, &nonBlocking)) |
| 125 |
|
{ |
| 126 |
|
DDrConsole_PrintF("failed to set non-blocking socket"); |
| 127 |
|
return false; |
| 128 |
< |
} |
| 129 |
< |
client_sock = sock; |
| 132 |
< |
client_address = address; |
| 128 |
> |
}*/ |
| 129 |
> |
//client_sock = sock; |
| 130 |
|
return sock; |
| 131 |
|
} |
| 132 |
|
|
| 136 |
– |
|
| 133 |
|
void NetUDPSocket_Close(int socket) |
| 134 |
|
{ |
| 135 |
|
closesocket(socket); |
| 139 |
|
{ |
| 140 |
|
//currently only protects against duplicate packets. |
| 141 |
|
int addr_size; |
| 142 |
< |
#ifdef TRACK_PACKETS |
| 142 |
> |
int sent_bytes; |
| 143 |
> |
#if 0 //#ifdef TRACK_PACKETS |
| 144 |
|
static uint32_t packet_index = 0; |
| 145 |
|
packet_index = (packet_index + 1); |
| 146 |
|
data->packet_index = packet_index; |
| 157 |
|
default: |
| 158 |
|
addr_size = sizeof(sockaddr_storage); |
| 159 |
|
} |
| 160 |
< |
return sendto(socket, data, datalen, 0, address, addr_size); |
| 160 |
> |
sent_bytes = sendto(socket, data, datalen, 0, address, addr_size); |
| 161 |
> |
|
| 162 |
> |
if(sent_bytes == SOCKET_ERROR) { |
| 163 |
> |
NetCatchError(); |
| 164 |
> |
} |
| 165 |
> |
|
| 166 |
> |
return sent_bytes; |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
#ifdef TRACK_PACKETS |
| 184 |
|
NetCatchError(); |
| 185 |
|
return false; |
| 186 |
|
} |
| 184 |
– |
} |
| 185 |
– |
/* |
| 186 |
– |
#ifdef TRACK_PACKETS |
| 187 |
– |
if(client_connected && !server_started) { |
| 188 |
– |
uint32_t index_mkr = ((flatline_packet*)(data))->packet_index; |
| 189 |
– |
//fancy way of checking if index_mkr is on one side of the max size of an int and last_packet is on the other |
| 190 |
– |
if( ((index_mkr - last_packet < 0x80000000) && (index_mkr > last_packet)) |
| 191 |
– |
//if it is, subtract half the size of an int from each. ^_^ |
| 192 |
– |
|| ((index_mkr - 0x80000000) > (last_packet - 0x80000000) ) ) |
| 193 |
– |
{ |
| 194 |
– |
return false; |
| 195 |
– |
} |
| 196 |
– |
else { |
| 197 |
– |
last_packet = index_mkr; |
| 198 |
– |
} |
| 187 |
|
} |
| 200 |
– |
|
| 201 |
– |
#endif |
| 202 |
– |
*/ |
| 203 |
– |
|
| 188 |
|
*datalen = msg_size; |
| 189 |
|
return true; |
| 190 |
|
|
| 191 |
|
} |
| 192 |
|
|
| 209 |
– |
|
| 210 |
– |
|
| 193 |
|
DWORD WINAPI StartServer(void* lol){ |
| 194 |
|
if(NetPlatform_Initalize() && FlatlineInitialize()) |
| 195 |
|
{ |