Created Networking (markdown)
parent
40e2600e60
commit
2ef5b18d1f
34
Networking.md
Normal file
34
Networking.md
Normal file
@ -0,0 +1,34 @@
|
||||
In order to use sockets in your homebrew application, you'll first need to initialize the SOC service by calling `SOC_Initialize()`. When your application finishes, use `SOC_Shutdown()` to close the service gracefully. The headers and documentation for these functions can be viewed here: [3ds/services/soc.h](https://github.com/smealum/ctrulib/blob/master/libctru/include/3ds/services/soc.h)
|
||||
|
||||
### Example
|
||||
|
||||
```c
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <3ds.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialize graphics and console
|
||||
gfxInitDefault();
|
||||
gfxSet3D(false);
|
||||
consoleInit(GFX_BOTTOM, NULL);
|
||||
|
||||
// Initialize SOC
|
||||
SOC_Initialize((u32*)memalign(0x1000, 0x128000), 0x128000);
|
||||
|
||||
// Do networking stuff
|
||||
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
// ...
|
||||
close(sockfd);
|
||||
|
||||
// Cleanup SOC
|
||||
SOC_Shutdown();
|
||||
|
||||
return 0
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user