本文整理汇总了C++中SDLNet_ResolveHost函数的典型用法代码示例。如果您正苦于以下问题:C++ SDLNet_ResolveHost函数的具体用法?C++ SDLNet_ResolveHost怎么用?C++ SDLNet_ResolveHost使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDLNet_ResolveHost函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect_request
int connect_request(REQUEST* req){
if(SDLNet_ResolveHost(&req->ip,req->host,req->host_port)==-1){
printf("connect_request: %s\n", SDLNet_GetError());
return false;
}
req->sock = SDLNet_TCP_Open(&req->ip);
if(!(req->sock)){
printf("connect_request: %s\n", SDLNet_GetError());
return false;
}
req->connected = true;
return true;
}
示例2: initialisationReseau
void initialisationReseau(char *strip,void (*backData)(Data*),void (*backList)(DataList*),void (*backGame)(DataGame*))
{
mCData = backData;
mCList= backList;
mCGame= backGame;
isQuitting=false;
printf("initialisationReseau: test\n");
if(isNetInitialised())
{
printf("initialisationReseau: réseau djà initialisé: libération des ressources\n");
sendQuit();
printf("Waiting for reception thread to reconnect\n");
int threadReturnValue;
SDL_WaitThread(threadRecept, &threadReturnValue);
printf("\nThread returned value: %d\n", threadReturnValue);
SDLNet_TCP_Close(sd);
}
else
{
if (SDLNet_Init() < 0)
{
printf("SDLNet_Init: %s\n", SDLNet_GetError());
return;
}
bufferLock = SDL_CreateMutex();
}
/* Resolve the host we are connecting to */
if (SDLNet_ResolveHost(&ip, strip, PORT) < 0)
{
printf("Can't resolve host: %s\n", SDLNet_GetError());
return;
}
/* Open a connection with the IP provided (listen on the host's port) */
if (!(sd = SDLNet_TCP_Open(&ip)))
{
printf("Can't open tcp connecting: %s\n", SDLNet_GetError());
return;
}
if(!bufferLock)
{
printf("initialisationReseau: ERROR can't create mutex\n");
}
//canRecept = SDL_CreateCond();
//canSend = SDL_CreateCond();
networkinitialised = 1;
}
示例3: SDLNet_Init
void Networking::serverConnect(){
SDLNet_Init();
if(SDLNet_ResolveHost(&serv_ip, NULL, PORT) == -1) {
printf("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
exit(0);
}
server_socket = SDLNet_TCP_Open(&serv_ip);
if(!server_socket){
printf("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
exit(0);
}
server_socketset = SDLNet_AllocSocketSet(3);
}
示例4: fprintf
//string mythVirtualServer::GetLocalAddress(){
// unsigned char iphost[4] = { 0 };
// IPaddress serverip;
// SDLNet_GetLocalAddress(&serverip);
// SDL_memcpy(iphost, &serverip.host, 4);
// char tmpstr[100] = { 0 };
// sprintf(tmpstr, "%d.%d.%d.%d", iphost[0], iphost[1], iphost[2], iphost[3]);
// return tmpstr;
//}
int mythVirtualServer::initalsocket(int port){
IPaddress serverIP;
int i;
unsigned char iphost[4] = {0};
/* Initialize SDL */
if ( SDL_Init(0) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
exit(1);
}
/* Initialize the network */
if ( SDLNet_Init() < 0 ) {
fprintf(stderr, "Couldn't initialize net: %s\n",
SDLNet_GetError());
SDL_Quit();
exit(1);
}
#pragma omp parallel for
/* Initialize the channels */
for ( i=0; i<CHAT_MAXPEOPLE; ++i ) {
people[i] = PEOPLE::CreateNew();
people[i]->addtionaldata = NULL;
people[i]->active = 0;
people[i]->sock = NULL;
}
/* Allocate the socket set */
socketset = SDLNet_AllocSocketSet(CHAT_MAXPEOPLE+1);
if ( socketset == NULL ) {
fprintf(stderr, "Couldn't create socket set: %s\n",
SDLNet_GetError());
cleanup(2);
}
/* Create the server socket */
SDLNet_ResolveHost(&serverIP, NULL, port);
//iphost[0] = &serverIP.host;
SDL_memcpy(iphost, &serverIP.host, 4);
printf("Server IP: %d.%d.%d.%d --- %d\n", iphost[0], iphost[1], iphost[2], iphost[3], port);
servsock = SDLNet_TCP_Open(&serverIP);
if ( servsock == NULL ) {
fprintf(stderr, "Couldn't create server socket: %s\n",
SDLNet_GetError());
cleanup(2);
}
SDLNet_TCP_AddSocket(socketset, servsock);
return 0;
}
示例5: SDLNet_Init
void Server::connect(Universe *_u){
u = _u;
SDLNet_Init();
SDLNet_ResolveHost(&ip,server,port);
sock = SDLNet_TCP_Open(&ip);
if (!sock){
printf("could not connect to %s:%d\n",server,port);
return;
}
set = SDLNet_AllocSocketSet(1);
SDLNet_TCP_AddSocket(set,sock);
send("name %s\n",myname);
last_ping_time = SDL_GetTicks();
}
示例6: SDLNet_ResolveHost
bool TCPConnection::ResolveHost()
{
int success = 0;
std::string serverOrClient;
if ( isServer )
{
// IP is null becasue this is a server
// Port is listening port
success = SDLNet_ResolveHost( &ipAddress, nullptr, portNr );
serverOrClient = "server";
}
else
{
// IP is the IP of the server
// Port is the port the serer listens on ( seea above )
success = SDLNet_ResolveHost( &ipAddress, hostName.c_str(), portNr );
serverOrClient = "client";
}
std::stringstream ss("");
ss << serverOrClient << "-" << hostName << " : " << portNr;
logger->Log( __FILE__, __LINE__, "Resolving host : ", ss.str() );
if ( success == -1 )
{
ss.str("");
ss << hostName << " : " << portNr <<" Error : " << SDLNet_GetError();
logger->Log( __FILE__, __LINE__, "Failed to resolve host : ", ss.str() );
return false;
}
logger->Log( __FILE__, __LINE__, "Host resolved!" );
return true;
}
示例7: cearthctx_new
cearth_ctx *
cearthctx_new(void)
{
cearth_ctx *ctx = calloc(1, sizeof(cearth_ctx));
/* Connect to server. */
ctx->sk = SDLNet_UDP_Open(0);
IPaddress ip;
SDLNet_ResolveHost(&ip, haven_serv, HAVENSERV_PORT);
int success = SDLNet_UDP_Bind(ctx->sk, -1, &ip);
/* TEST */
printf("Success: %d\n", success);
return ctx;
}
示例8: common_connect_server
int common_connect_server(IPaddress *host_ipaddress,TCPsocket *server_socket,Uint16 port,const char *host)
{
if(SDLNet_ResolveHost(host_ipaddress,host,port)!=0)
{
printf("\nUnable to initialize ipaddress for server");
return 0;
}
printf("\n I am listening on port %d",port);
if(!(*server_socket=SDLNet_TCP_Open(host_ipaddress)))
{
printf("\nUnable to initialize server socket:%s",SDLNet_GetError());
return 0;
}
return 1;
}
示例9: SDLNet_GetError
void TTCPServerSocket::listen (Uint16 port) {
IPaddress ip;
/* ip.host = INADDR_ANY */
if(SDLNet_ResolveHost(&ip,NULL,port) == -1) {
std::cerr << "SDLNet_ResolveHost: "<< SDLNet_GetError() << std::endl;
exit(1);
}
/* poslouchame pro prichozi spojeni z port-u*/
serversock=SDLNet_TCP_Open(&ip);
if(!serversock) {
std::cerr << "SDLNet_TCP_Open: " << SDLNet_GetError() << std::endl;
exit(2);
} else listening = true;
}
示例10: initialize_connection
void ClientConnection::initialize_connection() {
IPaddress ip;
if (SDLNet_ResolveHost(&ip, hostname.c_str(), _port) < 0) {
fprintf(stderr, "Error resolving host name '%s'\n", hostname.c_str());
} else {
_client_socket = SDLNet_TCP_Open(&ip);
if (!_client_socket) {
fprintf(stderr,
"Error resolving connecting to host '%s' with port %d\n",
hostname.c_str(), _port);
}
SDLNet_TCP_AddSocket(_socket_set, _client_socket);
}
}
示例11: net_init
bool net_init()
{
if ( SDLNet_Init() < 0 ) {
printf("SDLNet_Init: %s\n", SDLNet_GetError());
return false;
}
atexit(SDLNet_Quit);
IPaddress ip;
SDLNet_ResolveHost(&ip, "happy", 12521);
sprintf(szIPString, "%d.%d.%d.%d", ip.host & 0xff, (ip.host >> 8) & 0xff, (ip.host >> 16) & 0xff, (ip.host >> 24) & 0xff);
return true;
}
示例12: main
/* perform initialization and start up game loop */
int main(int argc, char *argv[])
{
int rval;
/* start up SDL and create window */
if (init() < 0) {
fprintf(stderr, "failed to initialize!\n");
rval = 1;
goto exit;
}
/* load media */
if (load_media() < 0) {
fprintf(stderr, "failed to load media!\n");
rval = 1;
goto exit;
}
/* networking setup */
/* these definitions need to be put in the global space */
IPaddress ip;
TCPsocket server = NULL;
TCPsocket client = NULL;
if (SDLNet_ResolveHost(&ip, NULL, 9999) < 0) {
fprintf(stderr, "SDLNet_ResolveHost: %s\n",
SDLNet_GetError());
rval = 1;
goto exit;
}
server = SDLNet_TCP_Open(&ip);
if (!server) {
fprintf(stderr, "SDLNet_TCP_Open: %s\n",
SDLNet_GetError());
rval = 1;
goto exit;
}
/* now listen for client */
goto exit;
while (!client) {
SDL_Delay(0);
client = SDLNet_TCP_Accept(server);
}
/* start game loop */
printf("starting loop\n");
game_loop();
rval = 0;
exit:
/* free resources and close SDL */
cleanup();
return rval;
}
示例13: sendQuery
void Server::sendQuery(const char* linkQuery) {
answer.clear();
if (SDLNet_ResolveHost(&hostIP, host, hostPort)) {
errorState = SERVER_RESOLVE_ERROR;
printErrorState(errorState, __LINE__);
return;
}
socket = SDLNet_TCP_Open(&hostIP);
logger("%d", socket);
if (socket == NULL) {
errorState = SOCKET_OPEN_ERROR;
printErrorState(errorState, __LINE__);
logger("%s", SDLNet_GetError());
exit(0);
return;
}
char *query = (char *) new char[HEAD_QUERY_SIZE + strlen(linkQuery) + TAIL_QUERY_SIZE];
char *answerBuffer = (char *) new char[STANDARD_QUERY_SIZE];
memset(query, 0, strlen(query));
strcat(query, HEAD_QUERY_STRING);
strcat(query, linkQuery);
strcat(query, TAIL_QUERY_STRING);
if (!(SDLNet_TCP_Send(socket, query, strlen(query)) != strlen(query))) // Ушли ли все данные? да-спрашиваем нет-в логгер.
while (true) { // пока данные поступают.
counters = SDLNet_TCP_Recv(socket, answerBuffer, STANDARD_QUERY_SIZE / 6); // 6 - unicodeLen
if (counters < 0) {
errorState = SOCKET_CONNECT_ERROR;
printErrorState(errorState, __LINE__);
break;
}
if (counters == 0) {
errorState = RECV_CLOSE_SUCCESSFUL;
printErrorState(errorState, __LINE__);
break;
}
for (unsigned int i = 0; i < counters; i++) answer.push_back(answerBuffer[i]);
} else {
errorState = QUERY_SEND_ERROR;
printErrorState(errorState, __LINE__);
}
delete[] query;
delete[] answerBuffer;
SDLNet_TCP_Close(socket);
socket = NULL;
}
示例14: IPX_StartServer
bool IPX_StartServer(Bit16u portnum) {
Bit16u i;
if(!SDLNet_ResolveHost(&ipxServerIp, NULL, portnum)) {
//serverSocketSet = SDLNet_AllocSocketSet(SOCKETTABLESIZE);
ipxServerSocket = SDLNet_UDP_Open(portnum);
if(!ipxServerSocket) return false;
for(i=0;i<SOCKETTABLESIZE;i++) connBuffer[i].connected = false;
TIMER_AddTickHandler(&IPX_ServerLoop);
return true;
}
return false;
}
示例15: rocsmq_init
TCPsocket rocsmq_init(p_rocsmq_baseconfig server) {
TCPsocket sock;
IPaddress ip;
/* create client information */
t_rocsmq_message message;
message.id[0] = '\0';
strncpy(message.sender,server->clientname,ROCS_CLIENTNAMESIZE);
p_rocsmq_clientdata cdata = (p_rocsmq_clientdata) message.tail;
strncpy(cdata->filter,server->filter, ROCS_IDSIZE);
strncpy(cdata->name,server->clientname,ROCS_CLIENTNAMESIZE);
/*
* verbindung aufbauen
*/
/* initialize SDL_net */
if(SDLNet_Init()==-1) return 0;
if(SDLNet_ResolveHost(&ip,server->serverip,server->port)==-1)
{
SDLNet_Quit();
return 0;
}
/* open the server socket */
sock=SDLNet_TCP_Open(&ip);
if(!sock)
{
SDLNet_Quit();
return 0;
}
log_message(DEBUG,"sending login info: %s\n", message.sender);
log_message(DEBUG," -- %d, %s \n", sock, message.tail);
/*
* send client data
*/
if (!rocsmq_send(sock,&message, 0)) {
return 0;
}
log_message(DEBUG, "successfully logged in");
return sock;
}