当前位置: 首页>>代码示例>>C++>>正文


C++ SDLNet_TCP_Close函数代码示例

本文整理汇总了C++中SDLNet_TCP_Close函数的典型用法代码示例。如果您正苦于以下问题:C++ SDLNet_TCP_Close函数的具体用法?C++ SDLNet_TCP_Close怎么用?C++ SDLNet_TCP_Close使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDLNet_TCP_Close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ngl_net_close_client

void
ngl_net_close_client(char num)
{
	if (num==0) {
		SDLNet_TCP_Close(csd0);
		quit=1;
		waiting0=1;
		reading0=0;
		printf("\nDesconectado el 0\n");
	}

	if (num==1) {
		SDLNet_TCP_Close(csd1);
		waiting1=1;
		reading1=0;
		printf("\nDesconectado el 1\n");
	}

	if (num==2) {
		SDLNet_TCP_Close(csd1);
		waiting2=1;
		reading2=0;
		printf("\nDesconectado el 2\n");
	}
}
开发者ID:ed00m,项目名称:NautilusGL,代码行数:25,代码来源:server.c

示例2: fix_nick

/* add a client into our array of clients */
Client *add_client(TCPsocket sock, char *name)
{
	fix_nick(name);
	if(!strlen(name))
	{
		putMsg(sock,"Invalid Nickname...bye bye!");
		SDLNet_TCP_Close(sock);
		return(NULL);
	}
	if(!unique_nick(name))
	{
		putMsg(sock,"Duplicate Nickname...bye bye!");
		SDLNet_TCP_Close(sock);
		return(NULL);
	}
	clients=(Client*)realloc(clients, (num_clients+1)*sizeof(Client));
	clients[num_clients].name=name;
	clients[num_clients].sock=sock;
	num_clients++;
	/* server side info */
	printf("--> %s\n",name);
	/* inform all clients, including the new one, of the joined user */
	send_all(mformat("ss","--> ",name));
	return(&clients[num_clients-1]);
}
开发者ID:Hellkipz,项目名称:Discord,代码行数:26,代码来源:tcpmultiserver.c

示例3: connection_connect

/*接続*/
void connection_connect(CONNECTION_DATA* con){
	/*変数宣言*/
	TCPsocket *sock = &con->socket;
	char* str;
	int content_length = -1;
	int is_err = false;
	FILE* log_file;
	/*接続先IPを取得*/
	con->ip = SDLNet_TCP_GetPeerAddress(*sock);
	/*ビジー状態に設定*/
	if(!lock_connection(con)){
		SDLNet_TCP_Close(*sock);
		return;
	}
	/*ヘッダを判断する*/
	str = NetUtl_readLine(sock);
	if(str == null){
		/*通信終わり*/
		SDLNet_TCP_Close(*sock);
		/*接続終了フラグ*/
		unlock_connection(con);
		return;
	}
	if(strncmp(str,POST_HEADER,strlen(POST_HEADER)) != 0){
		is_err = true;
	}
	/*とりあえず最後まで受信する。*/
	if(is_err){//エラー
		/*ログに追加*/
		log_file = lock_log_file();
		time_output();
		ip_output(con->ip);
		fprintf(log_file,"%s\n",str);
		unlock_log_file();
		//最後まで受信するだけ
		while(*(str = NetUtl_readLine(sock)) != END_CHAR){
		}
	}else{//ヘッダを取得する
		while(*(str = NetUtl_readLine(sock)) != END_CHAR){
			if(content_length < 0){
				if(strncmp(	str,
							CONTENT_LENGTH_HEADER,
							strlen(CONTENT_LENGTH_HEADER)
						) == 0){
					sscanf(str,CONTENT_LENGTH_HEADER_F,&content_length);
				}
			}//else if(){}
		}
	}
	if(!is_err && content_length >= 0){/*とりあえず通信するに値する*/
		connection_do_request(con,content_length);
	}else{/*まったく関係ない*/
		connection_send_error(sock);
	}
	/*通信終わり*/
	SDLNet_TCP_Close(*sock);
	/*接続終了フラグ*/
	unlock_connection(con);
}
开发者ID:ledyba,项目名称:Haduki,代码行数:60,代码来源:connection.c

示例4: SDLNet_TCP_Accept

void NetServer::handleserver()
{
	int which;
	unsigned char data;

	TCPsocket newsock = SDLNet_TCP_Accept(tcpsock);

	if (newsock == NULL)
		return;
	
	/* Look for unconnected person slot */
    for (which = 0; which < MAXCLIENTS; ++which) {
        if (!clients[which].sock) {
			break;
		}
	}

    if (which == MAXCLIENTS) {
		/* Look for inactive person slot */
        for (which = 0; which < MAXCLIENTS; ++which) {
            if (clients[which].sock && !clients[which].active) {
				/* Kick them out.. */
				data = NET_MSG_REJECT;
				SDLNet_TCP_Send(clients[which].sock, &data, 1);
				SDLNet_TCP_DelSocket(socketset, clients[which].sock);
				SDLNet_TCP_Close(clients[which].sock);
				numclients--;

#ifdef _DEBUG
				printf("Killed inactive socket %d\n", which);
#endif
				break;
			}
		}
	}

    if (which == MAXCLIENTS) {
		/* No more room... */
		data = NET_MSG_REJECT;
		SDLNet_TCP_Send(newsock, &data, 1);
		SDLNet_TCP_Close(newsock);

#ifdef _DEBUG
		printf("Connection refused -- server full\n");
#endif
    } else {
		/* Add socket as an inactive person */
		clients[which].sock = newsock;
		clients[which].peer = *SDLNet_TCP_GetPeerAddress(newsock);
		SDLNet_TCP_AddSocket(socketset, clients[which].sock);
		numclients++;

#ifdef _DEBUG
		printf("New inactive socket %d\n", which);
#endif
	}
}
开发者ID:hu9o,项目名称:smw-next,代码行数:57,代码来源:net.cpp

示例5: HandleServer

void HandleServer(void)
{
	TCPsocket newsock;
	int which;
	unsigned char data;

	newsock = SDLNet_TCP_Accept(servsock);
	if ( newsock == NULL ) {
		return;
	}

	/* Look for unconnected person slot */
	for ( which=0; which<CHAT_MAXPEOPLE; ++which ) {
		if ( ! people[which].sock ) {
			break;
		}
	}
	if ( which == CHAT_MAXPEOPLE ) {
		/* Look for inactive person slot */
		for ( which=0; which<CHAT_MAXPEOPLE; ++which ) {
			if ( people[which].sock && ! people[which].active ) {
				/* Kick them out.. */
				data = CHAT_BYE;
				SDLNet_TCP_Send(people[which].sock, &data, 1);
				SDLNet_TCP_DelSocket(socketset,
						people[which].sock);
				SDLNet_TCP_Close(people[which].sock);
#ifdef DEBUG
	fprintf(stderr, "Killed inactive socket %d\n", which);
#endif
				break;
			}
		}
	}
	if ( which == CHAT_MAXPEOPLE ) {
		/* No more room... */
		data = CHAT_BYE;
		SDLNet_TCP_Send(newsock, &data, 1);
		SDLNet_TCP_Close(newsock);
#ifdef DEBUG
	fprintf(stderr, "Connection refused -- chat room full\n");
#endif
	} else {
		/* Add socket as an inactive person */
		people[which].sock = newsock;
		people[which].peer = *SDLNet_TCP_GetPeerAddress(newsock);
		SDLNet_TCP_AddSocket(socketset, people[which].sock);
#ifdef DEBUG
	fprintf(stderr, "New inactive socket %d\n", which);
#endif
	}
}
开发者ID:BarleyStudio,项目名称:CorsixTH_Android,代码行数:52,代码来源:chatd.c

示例6: main_thread

void * main_thread(void * data)
{
	int flag=1,choice,n;
	int temp;
	TCPsocket client_socket,server_socket;
	if(!intialize_thread())
	{
		printf("\n Therer is some error while initializing thread");
		return 0;
	 }
	printf("\n Value of active ports is:%d",get_active_threads());

	// first server receive request from client to connect and open master server socket. To be created only once.-permanent 
	if(common_connect_server(&host_ipaddress,&server_socket,global_port,(const char *)NULL)==0)
		return (void *)1;
	while(quit) 
	{
		// Open client socket on server side for sending dynamic port address-temprary
		if((client_socket=SDLNet_TCP_Accept(server_socket)))
		{
 			// send port address to client
			pthread_mutex_lock(&mutex_variable);
			printf("\n Value of active ports:%d",get_active_threads());
			if(get_active_threads()==0)
			{
				int temp=0;
				SDLNet_TCP_Send(client_socket,&(temp),2);
				SDLNet_TCP_Close(client_socket);
				pthread_mutex_unlock(&mutex_variable);
			}
			else
				if(SDLNet_TCP_Send(client_socket,&(thread_header->client.port),2)==2)
				{
					printf("\nNew Port is send to client"); 
					// close temprary client socket 
					SDLNet_TCP_Close(client_socket);
					// opening port so that server can accept content from client in different thread;
					pthread_mutex_unlock(&mutex_variable);
					printf("\n Activating thread");
					activate_thread();
				}
		}
	}
		printf("\nEverything is OK now exiting");	
		SDLNet_TCP_Close(server_socket);
		cleanup_thread();
		return NULL;
}
开发者ID:deepakagg,项目名称:game-server,代码行数:48,代码来源:server_handle.c

示例7: SDLNet_TCP_Recv

void NetClient::handleserver()
{
	Uint8 data[512];
	int pos, len;
//	int used;

	/* Has the connection been lost with the server? */
	len = SDLNet_TCP_Recv(tcpsock, (char *)data, 512);

    if ( len <= 0 ) {
		SDLNet_TCP_DelSocket(socketset, tcpsock);
		SDLNet_TCP_Close(tcpsock);
		tcpsock = NULL;

    } else {
		pos = 0;
        while ( len > 0 ) {
			int used = handleserverdata(&data[pos]);
			pos += used;
			len -= used;
			
            if ( used == 0 ) {
				/* We might lose data here.. oh well,
				   we got a corrupt packet from server
				 */
				len = 0;
			}
		}
	}
}
开发者ID:hu9o,项目名称:smw-next,代码行数:30,代码来源:net.cpp

示例8: SDLNet_CheckSockets

void Users::process(){
    int n = SDLNet_CheckSockets(set, 0);
    if (n < 1) return;

    if (SDLNet_SocketReady(sock)){
        printf("new user...\n");
        TCPsocket newuser = SDLNet_TCP_Accept(sock);

        printf("Accepted...\n");
        User *u = new User(newuser);
        push_back(u);
        SDLNet_TCP_AddSocket(set,newuser);
    }

    User *u;
    for( iterator i = begin(); i != end(); i++ ){
        u = *i;
        if (SDLNet_SocketReady(u->sock)){
            int len;
            char buf[MAXLEN];
            if ((len = readLine(u->sock,buf,sizeof(buf))) > 0){
                fprintf(stderr,"got len=%d text from '%s': '%s'\n",len,u->name,buf);
                handle_command(buf,u);
            } else {
                printf("dead connection\n");
                SDLNet_TCP_DelSocket(set, u->sock);
                SDLNet_TCP_Close(u->sock);
                i = erase(i);
            }
        }
    }
}
开发者ID:qartis,项目名称:qonk,代码行数:32,代码来源:network.cpp

示例9: sprintf

void Server::Shutdown(){
    // send shutdown message
    for (map<int, PlayerObject*>::iterator j = playerObjects.begin(); j != playerObjects.end(); ++j){
        sprintf(outgoing, "4\n");
        SDLNet_TCP_Send(client_data[j->first].socket, outgoing, 17);
    }
    
    // clean up
    playerObjects.clear();
    gameObjects.clear();
    
    // close socket
    SDLNet_TCP_Close(server_socket);
    
    // destroy renderer
    SDL_DestroyRenderer(renderer);
    renderer = NULL;
    
    // close window
    SDL_DestroyWindow(window);
    window = NULL;
    
    // shutdown sdlnet
    SDLNet_Quit();
    
    // shutdown sdl
    SDL_Quit();
}
开发者ID:utzstauder,项目名称:cgl_st2016_semestertask,代码行数:28,代码来源:Server.cpp

示例10: SDLNet_TCP_DelSocket

/**
 * @brief Destructor
 *
 * Si #m_Socket no es nulo, se liberará el espacio en memoria que ocupa la estructura.
 * Además, se libera el espacio que ocupa el conjunto #set y cierra el socket m_Socket.
 */
CTcpSocket::~CTcpSocket() {
    if (!(m_Socket == NULL)) {
          SDLNet_TCP_DelSocket(set,m_Socket);
        SDLNet_FreeSocketSet(set);
        SDLNet_TCP_Close (m_Socket);
    }
}
开发者ID:wikiti,项目名称:ullPong,代码行数:13,代码来源:CNet.cpp

示例11: splitForSend

    int Connection::send(const inp::INFPacket& data){
        //  prepare packet for sending
        PacketList packList;
        splitForSend(data, packList);
        // if there is nothing to send, leave.
        if( packList.empty() ){ return 1; }

        ScopedMutexLock(pimpl_->dataAccess);
        if( pimpl_->userSocket != NULL ){
            //  Send packets in list
            for(size_t i = 0; i < packList.size(); ++i ){
                if( !packList[i].empty() ){
                    //check if everything went through
                    if( SDLNet_TCP_Send( pimpl_->userSocket, &packList[i][0], packList[i].size() ) < packList[i].size() )
                    {
                        SDLNet_TCP_Close( pimpl_->userSocket );
                        pimpl_->userSocket = NULL;
                        pimpl_->peer = NULL;
                        pimpl_->active = false;
                        pimpl_->connectTime = 0;
                        pimpl_->lastSent.clear();
                        return -1;
                    }
                }
            }
            pimpl_->lastSent = packList;
        } else {
            pimpl_->connectTime = 0;
            return -1;
        }
        return 1;
    }
开发者ID:Infraelly,项目名称:old-infraelly-engine,代码行数:32,代码来源:Connection.cpp

示例12: wait_for_greenlight

void
wait_for_greenlight()
{
  struct NetPacket pkt;
	int i;

	printf("CLIENT: Waiting for greenlight...\n");

	do {
		int rc;
		while ((rc = grabPacket(sock, socketset, &pkt)) == 0) {
			SDL_Delay(100);  /* nap and then try again. */
		}

		if (rc < 0) {
			printf("CLIENT: Lost connection.\n");
			SDLNet_TCP_Close(sock);
			exit(42);
		}
	} while (pkt.cmd != NETCMD_GREENLIGHT);

	printf("CLIENT: Got greenlight.\n");

	for (i = 0; i < JNB_MAX_PLAYERS; i++) {
		if (pkt.arg & (1 << i)) {
			printf("CLIENT: There is a player #%d.\n", i);
			player[i].enabled = 1;
		}
	}
}
开发者ID:esohns,项目名称:jnb,代码行数:30,代码来源:net.c

示例13: checkMouseMode3

//**************************************************************************
//*                   MODE 3 Lobby Screen                                  *
//**************************************************************************
static void checkMouseMode3(SDL_Event *event, SDL_Point *currentMouseLocation, SDL_Rect buttonPlacement[], int *select, int *mode, int modeMaxButtons[], bool *match, int *keyboardMode){
    for(int i=0; i < modeMaxButtons[3]; i++){
        if(mouseOnButton(currentMouseLocation, buttonPlacement, &i)){ // Is the mouse on button 'i' ?
            if(event->type == SDL_MOUSEBUTTONDOWN){
                *keyboardMode = ENTERING_TEXT;

                if(i == 2){                 // Ready
                    //playerReady = !playerReady;
                    SDLNet_TCP_Send(client.TCPSock, "#", strlen("#"));

                }
                else if(i == 1){            // Leave
                    isConnected = false;
                    SDLNet_TCP_Send(client.TCPSock, "-", strlen("-"));
                    SDLNet_TCP_Close(client.TCPSock);
                    SDLNet_UDP_Close(client.UDPRecvSock);
                    SDLNet_UDP_Close(client.UDPSendSock);

                    for(int i=0; i < MAX_PLAYERS; i++)
                        playerReady[i] = 0;

                    clearTextStrings(6);
                    printf("LEFT; '-' sent to server, socket closed, ready statuses cleared, textstrings cleared, mode changed\n"); //*****************************************
                    *mode = 5;
                }                           // (ELSE: Enter Chat Message Window Pressed)
            }
        }
    }
}
开发者ID:JonatanWang,项目名称:LearnMongoDB,代码行数:32,代码来源:inputhandler.c

示例14: SDL_WaitThread

ClientConnection::~ClientConnection()
{
	// Signal to stop
	status = -1;
	SDL_WaitThread(send_thread, NULL);

	// We don't need to lock because the send_thread is terminated
	while (data_to_send.size() > 0)
	{
		delete data_to_send.front().data;
		data_to_send.pop_front();
	}

	// make sure we don't trash messages when killing the thread.
	SDL_LockMutex(messages_mutex);
	SDL_KillThread(recieve_thread);
	SDL_UnlockMutex(messages_mutex);

	SDLNet_TCP_Close(socket);

	SDL_DestroyMutex(send_mutex);
	SDL_DestroyMutex(messages_mutex);

	// Remove this client from the world
	//entity->world->delete_entity(entity);
	//entity = 0;
}
开发者ID:FrimJo,项目名称:WolfSheep,代码行数:27,代码来源:clientconnection.cpp

示例15: main

int			main(int argc, char **argv)
{
  SDL_Rect		pos;
  t_world		new_world;
  t_bag			new_bag;
  SDLNet_SocketSet	set;

  if (signal(SIGINT, free_all) == SIG_ERR)
    exit(EXIT_FAILURE);
  if (argc != 3)
    write(2, USAGE, strlen(USAGE));
  else
    {
      init_buf_msg(&(gl_screen.my_msg));
      gl_screen.info_bag = &new_bag;
      gl_screen.pos = &pos;
      gl_screen.world = &new_world;
      init_screen(&gl_screen);
      init_net(argv[1], (unsigned)atoi(argv[2]), &set, &gl_screen);
      init_sdl(&gl_screen);
      events(&gl_screen, &set);
      SDLNet_FreeSocketSet(set);
      SDLNet_TCP_Close(gl_screen.sock_server);
      free_gui(&gl_screen);
    }
  return (EXIT_SUCCESS);
}
开发者ID:Sun42,项目名称:Zappy,代码行数:27,代码来源:main.c


注:本文中的SDLNet_TCP_Close函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。