글

2월, 2013의 게시물 표시

multi-platform TCP, UDP socket server

Just for Test! works on windows and linux ================================================================================= #ifdef WIN32 #ifndef _WINSOCKAPI_ #define _WINSOCKAPI_ #endif #endif #include <stdio.h> #ifdef WIN32 #pragma comment(lib, "ws2_32.lib") // Winsock 라이브러리 자동 링크 #include <windows.h> #include <winsock2.h> #define NET_INVALID_SOCKET INVALID_SOCKET #define NET_SOCKET_ERROR SOCKET_ERROR typedef int socklen_t; // unix 타입은 unsigned int, Windows는 int #else #include <sys/socket.h> // for socket(), bind(), connet() #include <sys/types.h> #include <arpa/inet.h> // for sockaddr_in, inet_ntoa() #include <unistd.h> // for close() #include <stdlib.h> // for exit() typedef int SOCKET; #define NET_INVALID_SOCKET -1 #define NET_SOCKET_ERROR -1 #endif #define MAXCONN 10 int receiveUDP(); int receiveTCP(); int main(){ #ifdef WIN32 //HANDLE thread ...