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


C++ SocketAddress::SetAddress方法代码示例

本文整理汇总了C++中SocketAddress::SetAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketAddress::SetAddress方法的具体用法?C++ SocketAddress::SetAddress怎么用?C++ SocketAddress::SetAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SocketAddress的用法示例。


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

示例1: test

void test()
{
	SocketAddress addr;
	addr.SetAddress("localhost:5000");
	GenericSocket genSock(SOCK_DGRAM);
	genSock.Bind(addr);
}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:7,代码来源:Main.cpp

示例2: Recibir

int UDPSocket::Recibir(void * data, int lenData, SocketAddress & from)
{
	sockaddr address;
	int longr = sizeof(address);
	recvfrom(GenericSocket::GetSock(), (char*)data, lenData, 0, &address, &longr);
	from.SetAddress(address);
	return 0;
}
开发者ID:DagorladFinite,项目名称:Prog,代码行数:8,代码来源:UDPSocket.cpp

示例3: networkState

//Al principio el estado de la red es UNINITIALIZED
NetworkClient::NetworkClient(std::string _addressServer, std::string _addressClient, std::string _nick):nick(_nick), networkState(NetworkState::UNINITIALIZED)
{
	saServer.SetAddress(_addressServer);
	SocketAddress myAddress;
	myAddress.SetAddress(_addressClient);
	int errBind = udpSocket.Bind(myAddress);
	int errBlock = udpSocket.NonBlocking(true);
	if (errBind > -1 && errBlock > -1)
	{
		//Si podemos hacer BIND y NONBLOCKING, pasamos a estado SAYINGHELLO
		//Este cliente empezará a buscar al servidor.
		networkState = NetworkState::SAYINGHELLO;
	}
}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:15,代码来源:NetworkClient.cpp

示例4: exception

Server::Server(std::string _serverAddress, int _numPlayers)
{
	aWords.LoadDefault();
	//Inicializar el socket de dispatcher

	//Ponerlo a Bind y a Listen

	SocketAddress sa;
	sa.SetAddress(_serverAddress);
	int err = dispatcher.Bind(sa);
	if (err == -1)
	{
		throw std::exception("Error en Server::Server");
	}
	err = dispatcher.Listen(_numPlayers);
	if (err == -1)
	{
		throw std::exception("Error en listen");
	}
}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:20,代码来源:Server.cpp

示例5: Cliente

void Cliente(std::string direccionDestino)
{
	UDPSocket udpSocket;
	SocketAddress saDestino;
	saDestino.SetAddress(direccionDestino);
	udpSocket.NonBlocking(true);
	while (true)
	{
		char datos[1300];
		int len = StringTools::PideDatosTeclado(datos);

		int bytesSend = udpSocket.SendTo(datos, len, saDestino);
		if (bytesSend > 0)
		{
			if (strcmp(datos, "exit") == 0)
			{
				break;
			}
		}
	}
}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:21,代码来源:main.cpp

示例6: routine

void routine(std::string direccion,int conexiones) {

	//Creamos el socket de dispatching para saber cuando se nos conectan
	TCPSpcket dispatchSock;
	SocketAddress addressReceive;
	addressReceive.SetAddress(direccion);
	dispatchSock.Bind(addressReceive);
	std::vector<std::shared_ptr<TCPSpcket>> clientList;
	dispatchSock.Listen(conexiones);

	SocketAddress comesFrom;

	for (int i = 0; i < conexiones; i++)
	{
		clientList.push_back(dispatchSock.Accept(comesFrom));

	}
	
	sendToAll(clientList,"BEGIN",conexiones);
	

}
开发者ID:DagorladFinite,项目名称:Prog,代码行数:22,代码来源:main.cpp

示例7:

NetworkServer::NetworkServer(std::string _strServerAddress)
{

	SocketAddress saServer;
	saServer.SetAddress(_strServerAddress);
	//TODO: No se están controlando errores de Bind y NonBlocking
	udpSocket.Bind(saServer);
	udpSocket.NonBlocking(true);

	//Forzamos que los jugadores estén desconectados
	//También nos aseguramos de que las posiciones iniciales de los jugadores
	//en el servidor corresponden con las de los clientes.
	//Esto es muy importante para asegurarnos de que el movimiento relativo
	//y el dispatch "absolutista" del servidor tienen los valores correctos.
	for (int i = 0; i < 4; i++)
	{
		playerList[i].connected = false;
		playerList[i].position = 10;
		playerList[i].antiCheatCount = 0;
	}

	

}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:24,代码来源:NetworkServer.cpp

示例8: Servidor

void Servidor(std::string direccion)
{
	SocketAddress sa;
	sa.SetAddress(direccion);
	UDPSocket udpSocket;
	udpSocket.Bind(sa);
	udpSocket.NonBlocking(true);
	while (true)
	{
		char datos[1300];
		SocketAddress from;
		
		int bytesReceived = udpSocket.ReceiveFrom(datos, 1300, from);
		if (bytesReceived > 0)
		{
			datos[bytesReceived] = '\0';
			std::cout << "Recibo de "<<from<<": " << datos << std::endl;
			if (strcmp(datos, "exit") == 0)
			{
				break;
			}
		}
	}
}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:24,代码来源:main.cpp


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