98
edits
RossyMiles (talk | contribs) mNo edit summary |
RossyMiles (talk | contribs) No edit summary |
||
Line 9: | Line 9: | ||
These functions provide all the platform specific functionality required by Net*. | These functions provide all the platform specific functionality required by Net*. | ||
bool '''NetPlatform_Initalize''' | bool '''NetPlatform_Initalize()'''<br> | ||
This function is called when the network functionality is required. On Windows, it makes a call to WSAStartup. | This function is called when the network functionality is required. On Windows, it makes a call to WSAStartup. On other platforms it is not needed as sockets are initialized by default for every process. | ||
void '''NetPlatform_Shutdown''' | void '''NetPlatform_Shutdown()'''<br> | ||
For every call to NetPlatform_Initalize, there has to be a corresponsing call to NetPlatform_Shutdown. On Windows, this function calls WSACleanup. | For every call to NetPlatform_Initalize, there has to be a corresponsing call to NetPlatform_Shutdown. On Windows, this function calls WSACleanup. On other platforms it is not needed as sockets are initialized by default for every process. | ||
=== NetUPnP_* === | === NetUPnP_* === | ||
These functions provide basic automatic port forwarding for computers behind a router. | These functions provide basic automatic port forwarding for computers behind a router. | ||
bool '''NetUPnP_Initalize''' | bool '''NetUPnP_Initalize('''char** '''localip''', char** '''routerip)'''<br> | ||
Initializes the UPnP library. Places the local ip address in localip and places the router's ip address in routerip. | Initializes the UPnP library. Places the local ip address in localip and places the router's ip address in routerip. | ||
bool '''NetUPnP_Shutdown''' | bool '''NetUPnP_Shutdown()'''<br> | ||
Closes the UPnP library. Frees the strings pointed to by localip and routerip. | Closes the UPnP library. Frees the strings pointed to by localip and routerip. | ||
Line 27: | Line 27: | ||
These functions provide a basic UDP sockets library. | These functions provide a basic UDP sockets library. | ||
int '''NetUDPSocket_Create''' | int '''NetUDPSocket_Create('''uint16_t '''port)'''<br> | ||
Creates a new, non-blocking, UDP socket and binds it to the port specified. If the specified port is 0, the socket is automatically bound to an unused port. | Creates a new, non-blocking, UDP socket and binds it to the port specified. If the specified port is 0, the socket is automatically bound to an unused port. | ||
bool '''NetUDPSocket_Close''' | bool '''NetUDPSocket_Close('''int '''socket)'''<br> | ||
Destroys a UDP socket created with NetUDPSocket_Create. | Destroys a UDP socket created with NetUDPSocket_Create. | ||
bool '''NetUDPSocket_Send''' | bool '''NetUDPSocket_Send('''int '''socket''', sockaddr_in/sockaddr_in6 '''address''', const char* '''data''', uint16_t '''datalen)'''<br> | ||
Sends a packet of data to the specified address using the specified socket. To broadcast a message across a LAN (such as when checking for available games), send it to 255.255.255.255 (IPv4 only). | Sends a packet of data to the specified address using the specified socket. To broadcast a message across a LAN (such as when checking for available games), send it to 255.255.255.255 (IPv4 only). | ||
bool '''NetUDPSocket_Recieve''' | bool '''NetUDPSocket_Recieve('''int '''socket''', char* '''data''', uint16_t* '''datalen''', sockaddr_in*/sockaddr_in6* '''address)'''<br> | ||
Recieves a single packet from the specified socket. Places the received data in | Recieves a single packet from the specified socket. Places the received data in '''data''', the length of the data returned in '''datalen''', and the address the packet was received from in '''address'''. If there are no packets in the buffer, the function returns immediately. | ||
=== NetUDPServer_* === | |||
These functions provide a basic, single-threaded, blocking UDP server. | |||
int '''NetUDPServer_Run('''uint16_t '''port''', bool (*'''packet_callback''')'''('''char* '''data''', uint16_t '''datalen''', int '''from))'''<br> | |||
Starts a new UDP server on the specified port which calls '''packet_callback''' when a packet is recieved. Does not return until the server has finished running ('''packet_callback''' returns false). | |||
bool '''NetUDPServer_Send('''sockaddr_in/sockaddr_in6 '''address''', const char* '''data''', uint16_t '''datalen)'''<br> | |||
Sends a packet of data to the specified address using the server running on the current thread. This function should only be called from '''packet_callback''' or functions called by '''packet_callback'''. |
edits