示例#1
0
void CUDPServer::sendAll(CUDPPacket poPacket)
{
	UDPsocket oSocket;
	int i, iResult;
	IPaddress *poIPAddress;
	
	oSocket=SDLNet_UDP_Open(0);
	if(!oSocket) 
	{
		printf("SDLNet_UDP_Open: %s\n", SDLNet_GetError());
	}	

	for ( i = 0 ; i < goClientManager.getNumberClients() ; i++ )
	{
		poIPAddress = goClientManager.getIPAddress(i);

		iResult = SDLNet_UDP_Bind( oSocket, -1, poIPAddress );
		if( iResult == -1 ) 
		{
			printf("SDLNet_UDP_Bind: %s\n", SDLNet_GetError());
			// do something because we failed to bind
		}
		poPacket.send(oSocket, MSG_TEXTMESSAGE);
		SDLNet_UDP_Unbind( oSocket, iResult );
	}	
	SDLNet_UDP_Close( oSocket );

}
示例#2
0
static void NET_FreeNodenum(INT32 numnode)
{
	// can't disconnect from self :)
	if (!numnode)
		return;

	DEBFILE(va("Free node %d (%s)\n", numnode, NET_GetNodeAddress(numnode)));

	SDLNet_UDP_Unbind(mysocket,numnode-1);

	memset(&clientaddress[numnode], 0, sizeof (IPaddress));
}
示例#3
0
文件: net.cpp 项目: Timo6/trackeditor
bool NET::Connect(string host, int port)
{
	server = false;
	bool err = false;
	
	if (host == "Server")
		server = true;
	
	if (remote_socket != NULL)
	{
		SDLNet_UDP_Close(remote_socket);
		remote_socket = NULL;
	}
	
	if (server)
		remote_socket = SDLNet_UDP_Open(port);
	else
		remote_socket = SDLNet_UDP_Open(0);
	
	if (!server)
	{
		SDLNet_ResolveHost(&remote_ip, host.c_str(), port);
		
		SDLNet_UDP_Unbind(remote_socket, 0);
		if (SDLNet_UDP_Bind(remote_socket, 0, &remote_ip)==-1)
		{
			err = true;
			
			if (NET_DEBUG)
			{
				cout << "net:  couldn't bind UDP socket to host " << host << " port " << port << endl;
				printf("SDLNet_UDP_Bind: %s\n",SDLNet_GetError());
			}
		}
	}
	
	//try a handshake
	if (pout == NULL)
		pout = SDLNet_AllocPacket(MAX_PACKET_SIZE);
	if (pin == NULL)
		pin = SDLNet_AllocPacket(MAX_PACKET_SIZE);

	if (server)
	{
	}
	else
	{
		err = ClientHandshake();
	}
	
	return !err;
}
示例#4
0
Peer::~Peer() {
	//SDLNet_FreeSocketSet(watch);
	
	for(auto i : sockets)
	{
		SDLNet_UDP_DelSocket(watch,i);
		for (int c=0;c<SDLNET_MAX_UDPCHANNELS-1;c++)
		{
			SDLNet_UDP_Unbind(i, c);
		}	
		SDLNet_UDP_Close(i);
	}
	//SDLNet_FreeSocketSet(watch); still causes segfault here too, damn
}
示例#5
0
/* I_Disconnect
 *
 * Disconnect from server
 */
void I_Disconnect(void)
{
/*  int i;
  UDP_PACKET *packet;
  packet_header_t *pdata = (packet_header_t *)packet->data;
  packet = I_AllocPacket(sizeof(packet_header_t) + 1);

  packet->data[sizeof(packet_header_t)] = consoleplayer;
        pdata->type = PKT_QUIT; pdata->tic = gametic;

  for (i=0; i<4; i++) {
    I_SendPacket(packet);
    I_uSleep(10000);
    }
  I_FreePacket(packet);*/
  SDLNet_UDP_Unbind(udp_socket, 0);
}
示例#6
0
文件: net.cpp 项目: Timo6/trackeditor
//this function assumes pin already has an incoming packet from the client
bool NET::ServerHandshake()
{
	string handshake = HANDSHAKESTR;
	string handshake_reply = HANDSHAKEREPLYSTR;
//	int timeout = HANDSHAKETIMEOUT;
	
	bool err = false;
	
	if (IsEqualToPacket(pin, CONTROL_HANDSHAKE, (void *) handshake.c_str(), handshake.length()))
	{
		SDLNet_UDP_Unbind(remote_socket, 0);
		if (SDLNet_UDP_Bind(remote_socket, 0, &(pin->address))==-1)
		{
			err = true;
			
			if (NET_DEBUG)
			{
				cout << "net:  couldn't bind UDP socket to host " << SDLNet_ResolveIP(&(pin->address)) << endl;
				printf("SDLNet_UDP_Bind: %s\n",SDLNet_GetError());
			}
		}
		WriteToPacket(pout, CONTROL_HANDSHAKE, (void *) handshake_reply.c_str(), handshake_reply.length());
		UDPSend(pout, 0);
		connected = true;
		if (NET_DEBUG)
			cout << "net:  incoming connection established" << endl;
	}
	else 
	{
		if (NET_DEBUG)
			cout << "net:  Invalid handshake from " << SDLNet_ResolveIP(&(pin->address)) << endl;
		err = true;
	}
	
	return err;
}
示例#7
0
int network_udp_unbind(UDPsocket udp, int channel) {
        SDLNet_UDP_Unbind(udp, channel);
        network_udp_close(udp);
        return 0;
}
示例#8
0
void UDPNetwork::Unbind(int channel)
{
	SDLNet_UDP_Unbind(m_socket, channel);
}
示例#9
0
void I_UnRegisterPlayer(UDP_CHANNEL channel)
{
  SDLNet_UDP_Unbind(udp_socket, channel);
}
示例#10
0
/*
* network_udp_unbind() - Unbind the given socket from the given channel and close it
* @udp: the socket to unbind
* @channel: the channel to unbind from
*/
int network_udp_unbind(UDPsocket* udp, int channel) {
	SDLNet_UDP_Unbind(*udp, channel); // Unbind the socket
	network_udp_close(udp); // Close the socket
	return 0; // Return 0 on success
}