started netcode playing with basic functionality
This commit is contained in:
63
net/client.c
Normal file
63
net/client.c
Normal file
@@ -0,0 +1,63 @@
|
||||
//troy Rosin
|
||||
|
||||
#include <SDL2/SDL_net.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <mydebug.h>
|
||||
#include <net.h>
|
||||
|
||||
|
||||
|
||||
char buf[PACKSZ];
|
||||
char pack[PACKSZ];
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
IPaddress ip;
|
||||
TCPsocket sock;
|
||||
int ret = 0;
|
||||
|
||||
SDL_Init(0);
|
||||
|
||||
SDLNet_Init();
|
||||
|
||||
if(SDLNet_ResolveHost(&ip, SERVER, PORT) == -1)
|
||||
{
|
||||
printf("SDLNet_resolvehost error: %s\n", SDLNet_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sock = SDLNet_TCP_Open(&ip);
|
||||
if(!sock)
|
||||
{
|
||||
printf("SDL_Net_TCP_Open error: %s\n", SDLNet_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = SDLNet_TCP_Recv(sock, pack, PACKSZ);
|
||||
if(ret <=0 )
|
||||
{
|
||||
printf("error in TCP Recv: %s\n", SDLNet_GetError());
|
||||
}
|
||||
|
||||
read_to_buff(buf, pack, PACKSZ);
|
||||
|
||||
printf("got msg: %s\n", buf);
|
||||
|
||||
|
||||
SDLNet_TCP_Close(sock);
|
||||
SDLNet_Quit();
|
||||
SDL_Quit();
|
||||
|
||||
puts("donzo");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user