本文整理汇总了C++中enet_address_set_host函数的典型用法代码示例。如果您正苦于以下问题:C++ enet_address_set_host函数的具体用法?C++ enet_address_set_host怎么用?C++ enet_address_set_host使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enet_address_set_host函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: CHECK
Peer* ClientHost::Connect(
std::string server_ip,
uint16_t port,
size_t channel_count
) {
CHECK(_state == STATE_INITIALIZED);
ENetAddress address;
if (enet_address_set_host(&address, server_ip.c_str()) != 0) {
// THROW_ERROR("Unable to set enet host address!");
return NULL;
}
address.port = port; // XXX: type cast.
ENetPeer* enet_peer = enet_host_connect(_host, &address, channel_count, 0);
if (enet_peer == NULL) {
// THROW_ERROR("Enet host is unable to connect!");
return NULL;
}
Peer* peer = Host::_GetPeer(enet_peer);
CHECK(peer != NULL);
return peer;
}
开发者ID:xairy,项目名称:enet-plus,代码行数:25,代码来源:client_host.cpp
示例2: initEnet
static int initEnet(const char *host_ip, const int host_port, ServerData *data)
{
ENetAddress address;
assert(data);
if (enet_initialize() != 0) {
fprintf (stderr, "An error occurred while initializing ENet.\n");
return RETURN_FAIL;
}
address.host = ENET_HOST_ANY;
address.port = host_port;
if (host_ip)
enet_address_set_host(&address, host_ip);
data->server = enet_host_create(&address,
32 /* max clients */,
2 /* max channels */,
0 /* download bandwidth */,
0 /* upload bandwidth */);
if (!data->server) {
fprintf (stderr,
"An error occurred while trying to create an ENet server host.\n");
return RETURN_FAIL;
}
/* enable compression */
data->server->checksum = enet_crc32;
enet_host_compress_with_range_coder(data->server);
return RETURN_OK;
}
开发者ID:Cloudef,项目名称:srv.birth,代码行数:34,代码来源:main.c
示例3: printf
void CC_Client::connect(const char *host=HOST, uint16_t port=PORT) {
if (connected) {
printf("Connected already.\n");
return;
}
enet_address_set_host(&address, host);
address.port = port;
peer = enet_host_connect(client, &address, 2, 0);
if (peer == NULL) {
fprintf(stderr, "No available peers to connect\n");
exit(EXIT_FAILURE);
}
if (enet_host_service(client, &evt, 5000) > 0
&& evt.type == ENET_EVENT_TYPE_CONNECT) {
printf("Connected to server %s:%u\n", HOST, PORT);
connected = true;
} else {
enet_peer_reset(peer);
printf("Connection failed to %s:%u\n", HOST, PORT);
}
//~ conn_t_ret = pthread_create(&conn_t, NULL, CC_Client::loop, (void*)this);
}
开发者ID:noko3,项目名称:cc-client,代码行数:27,代码来源:client.cpp
示例4: ENSURE
bool CNetClientSession::Connect(u16 port, const CStr& server)
{
ENSURE(!m_Host);
ENSURE(!m_Server);
// Create ENet host
ENetHost* host = enet_host_create(NULL, 1, CHANNEL_COUNT, 0, 0);
if (!host)
return false;
// Bind to specified host
ENetAddress addr;
addr.port = port;
if (enet_address_set_host(&addr, server.c_str()) < 0)
return false;
// Initiate connection to server
ENetPeer* peer = enet_host_connect(host, &addr, CHANNEL_COUNT, 0);
if (!peer)
return false;
m_Host = host;
m_Server = peer;
m_Stats = new CNetStatsTable(m_Server);
if (CProfileViewer::IsInitialised())
g_ProfileViewer.AddRootTable(m_Stats);
return true;
}
开发者ID:Gavinator98,项目名称:0ad,代码行数:30,代码来源:NetSession.cpp
示例5: renet_connection_initialize
VALUE renet_connection_initialize(VALUE self, VALUE host, VALUE port, VALUE channels, VALUE download, VALUE upload)
{
rb_funcall(mENet, rb_intern("initialize"), 0);
Connection* connection;
/* Now that we're releasing the GIL while waiting for enet_host_service
we need a lock to prevent potential segfaults if another thread tries
to do an operation on same connection */
VALUE lock = rb_mutex_new();
rb_iv_set(self, "@lock", lock);
rb_mutex_lock(lock);
Data_Get_Struct(self, Connection, connection);
Check_Type(host, T_STRING);
if (enet_address_set_host(connection->address, StringValuePtr(host)) != 0)
{
rb_raise(rb_eStandardError, "Cannot set address");
}
connection->address->port = NUM2UINT(port);
connection->channels = NUM2UINT(channels);
connection->online = 0;
connection->host = enet_host_create(NULL, 1, connection->channels, NUM2UINT(download), NUM2UINT(upload));
if (connection->host == NULL)
{
rb_raise(rb_eStandardError, "Cannot create host");
}
rb_iv_set(self, "@total_sent_data", INT2FIX(0));
rb_iv_set(self, "@total_received_data", INT2FIX(0));
rb_iv_set(self, "@total_sent_packets", INT2FIX(0));
rb_iv_set(self, "@total_received_packets", INT2FIX(0));
rb_mutex_unlock(lock);
return self;
}
开发者ID:jvranish,项目名称:rENet,代码行数:34,代码来源:renet_connection.c
示例6: enet_address_set_host
void NetworkController::initEnet() {
if( enet_initialize() != 0){
root->fatalError("NetController", "Cannot initialise ENet");
};
root->sout << "Attempting to create host..." << endl;
if( root->confMgr.varExists("host_address") ){
enet_address_set_host( &enetAddress, root->confMgr.getVarS("host_address").c_str() );
root->sout << "Binding to configured address " << root->confMgr.getVarS("host_address") <<endl;
}else{
enetAddress.host = ENET_HOST_ANY;
root->sout << "Binding to any available address" << endl;
}
if( root->confMgr.varExists("host_port") ){
enetAddress.port = root->confMgr.getVarI("host_port");
}else{
enetAddress.port = HOST_PORT_DEFAULT;
}
root->sout << "Binding to port " << enetAddress.port << endl;
enetHost = enet_host_create(&enetAddress, (root->confMgr.varExists("max_clients")) ? (root->confMgr.getVarI("max_clients")) : MAX_CLIENTS_DEFAULT, 2, 0, 0);
if(enetHost == NULL) {
root->fatalError("NetController", "Cannot create ENet host");
}
}
开发者ID:cindustries,项目名称:engine-cuboid,代码行数:30,代码来源:NetworkController.cpp
示例7: room_data_change
NetClient::NetClient(const std::string& ip)
:
me (0),
server (0),
exit (false),
is_game (false),
game_start (false),
game_end (false),
room_data_change (false),
player_data_change(false),
level_change (false),
updates_change (0),
ourself (players.begin()) // will crash if dereferenced if empty
{
// 0 = Client, 1 = one connection at most (to server), 0, 0 = unlim. bandw.
//
// #############################################################
// # NOTE: If you get a compiler error for the following line, #
// # check your enet version. Lix assumes you have enet 1.3. #
// #############################################################
me = enet_host_create(0, 1, LEMNET_CHANNEL_MAX, 0, 0);
ENetAddress address;
enet_address_set_host(&address, ip.c_str());
address.port = gloB->server_port;
server = enet_host_connect(me, &address, LEMNET_CHANNEL_MAX, 0);
}
开发者ID:AmandaBayless,项目名称:Lix,代码行数:28,代码来源:client.cpp
示例8: Disconnect
bool NNetwork::Connect(std::string i_HostName, unsigned int Port)
{
if (Host)
{
Disconnect();
}
HostName = i_HostName;
Address.port = Port;
enet_address_set_host(&Address, HostName.c_str());
Host = enet_host_connect(Client,&Address,2,0);
if (!Host)
{
std::stringstream Message;
Message << "Failed to connect to host " << HostName << " on port " << Port << "!";
GetGame()->GetLog()->Send("NETWORK",0,Message.str());
return 1;
}
ENetEvent Event;
if (enet_host_service(Client, &Event, 2500) > 0 && Event.type == ENET_EVENT_TYPE_CONNECT)
{
std::stringstream Message;
Message << "Successfully connected to " << HostName << " on port " << Port << ".";
GetGame()->GetLog()->Send("NETWORK",2,Message.str());
return 0;
} else {
std::stringstream Message;
Message << "Failed to connect to host " << HostName << " on port " << Port << "!";
GetGame()->GetLog()->Send("NETWORK",0,Message.str());
Host = NULL;
return 1;
}
return 1;
}
开发者ID:ZenX2,项目名称:Astrostruct,代码行数:34,代码来源:NNetwork.cpp
示例9: enet_address_set_host
int NetworkManager::connexionToHost(std::string url,int port)
{
enet_address_set_host (& address,url.c_str());
address.port = port;
peer = enet_host_connect (client, & address, 2, 0);
if (peer == NULL)
{
return 1;
}
if (enet_host_service (client, &eventClient, 1000) > 0 && eventClient.type == ENET_EVENT_TYPE_CONNECT)
{
isConnectedflag = true;
endThread = false;
thread = boost::thread(&NetworkManager::threadConnexion, (void *) this);
return 0;
}
else
{
/* Either the 5 seconds are up or a disconnect event was */
/* received. Reset the peer in the event the 5 seconds */
/* had run out without any significant event. */
enet_peer_reset (peer);
return 2 ;
}
}
开发者ID:quinsmpang,项目名称:xsilium-engine,代码行数:25,代码来源:NetworkManager.cpp
示例10: resolverloop
int resolverloop(void * data)
{
resolverthread *rt = (resolverthread *)data;
for(;;)
{
SDL_SemWait(resolversem);
SDL_LockMutex(resolvermutex);
if(resolverqueries.empty())
{
SDL_UnlockMutex(resolvermutex);
continue;
}
rt->query = resolverqueries.pop();
rt->starttime = lastmillis;
SDL_UnlockMutex(resolvermutex);
ENetAddress address = { ENET_HOST_ANY, CUBE_SERVINFO_PORT };
enet_address_set_host(&address, rt->query);
SDL_LockMutex(resolvermutex);
resolverresult &rr = resolverresults.add();
rr.query = rt->query;
rr.address = address;
rt->query = NULL;
rt->starttime = 0;
SDL_UnlockMutex(resolvermutex);
};
return 0;
};
开发者ID:Knapsack44,项目名称:w,代码行数:27,代码来源:serverbrowser.cpp
示例11: enet_address_set_host
void networkEngine::serverSetup()
{
//gameEngine *gameE = gameEngine::Instance();
boost::shared_ptr<gameEngine> gameE = gameEngine::Instance();
/* Bind the server to the default localhost. */
/* A specific host address can be specified by */
/* enet_address_set_host (& address, "x.x.x.x"); */
// Old Pre-GUI ip address input code
// string ipAddress;
// cout << "IP Address to bind to:" << endl;
// cin >> ipAddress;
listenAddress.host = enet_address_set_host (& listenAddress, ipAddress.c_str());
// listenAddress.host = enet_address_set_host (& listenAddress, ENET_HOST_ANY);
/* Bind the server to port 1234. */
listenAddress.port = 1234;
server = enet_host_create (& listenAddress /* the address to bind the server host to */,
32 /* allow up to 32 clients and/or outgoing connections */,
2 /* allows up to 2 channels, 0, 1*/,
0 /* assume any amount of incoming bandwidth */,
0 /* assume any amount of outgoing bandwidth */);
if (server == NULL)
{
logMsg("An error occurred while trying to create an ENet server host.");
exit (EXIT_FAILURE);
}
gameE->setServerRunning(true);
}
开发者ID:libolt,项目名称:ubc-merge,代码行数:32,代码来源:networkengine.cpp
示例12: menu_connect_start
void menu_connect_start(component *c, void *userdata) {
scene *s = userdata;
connect_menu_data *local = menu_get_userdata(c->parent);
ENetAddress address;
const char *addr = textinput_value(local->addr_input);
s->gs->role = ROLE_CLIENT;
// Free old saved address, and set new
free(settings_get()->net.net_connect_ip);
settings_get()->net.net_connect_ip = strdup(addr);
// Set up enet host
local->host = enet_host_create(NULL, 1, 2, 0, 0);
if(local->host == NULL) {
DEBUG("Failed to initialize ENet client");
return;
}
// Disable connect button and address input field
component_disable(local->connect_button, 1);
component_disable(local->addr_input, 1);
menu_select(c->parent, local->cancel_button);
// Set address
enet_address_set_host(&address, addr);
address.port = settings_get()->net.net_connect_port;
ENetPeer *peer = enet_host_connect(local->host, &address, 2, 0);
if(peer == NULL) {
DEBUG("Unable to connect to %s", addr);
enet_host_destroy(local->host);
local->host = NULL;
}
time(&local->connect_start);
}
开发者ID:exander77,项目名称:openomf,代码行数:35,代码来源:menu_connect.c
示例13: mPlayerFactory
NetManager::NetManager(bool isServer, const FAWorld::PlayerFactory& playerFactory) : mPlayerFactory(playerFactory)
{
assert(singletonInstance == NULL);
singletonInstance = this;
enet_initialize();
mAddress.port = 6666;
mIsServer = isServer;
if(isServer)
{
mAddress.host = ENET_HOST_ANY;
mHost = enet_host_create(&mAddress, 32, 2, 0, 0);
}
else
{
enet_address_set_host(&mAddress, "127.0.0.1");
mHost = enet_host_create(NULL, 32, 2, 0, 0);
mServerPeer = enet_host_connect(mHost, &mAddress, 2, 0);
ENetEvent event;
if(enet_host_service(mHost, &event, 5000))
{
std::cout << "connected" << std::endl;
}
else
{
std::cout << "connection failed" << std::endl;
}
}
}
开发者ID:FlyingTarrasque,项目名称:freeablo,代码行数:35,代码来源:netmanager.cpp
示例14: enet_host_create
void *Network::readThread(void *context)
{
struct thread_args *args = (struct thread_args *)context;
char *ip = args->ip;
Network *instance = args->instance;
ENetEvent event;
ENetAddress address;
client = enet_host_create(NULL, 1, 1, 0, 0);
if (client == NULL)
return (void*)1;
enet_address_set_host (&address, ip);
address.port = 1400;
server = enet_host_connect (client, &address, 1, 0);
if (server == NULL)
return (void*)2;
if (!(enet_host_service (client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT))
return (void*)3;
emit instance->connected();
while(true) {
pthread_mutex_lock(&net_mutex);
enet_host_service (client, &event, 0);
pthread_mutex_unlock(&net_mutex);
switch (event.type) {
case ENET_EVENT_TYPE_CONNECT:
server = event.peer;
emit instance->connected();
break;
case ENET_EVENT_TYPE_RECEIVE:
switch(event.packet->data[0]) {
case SET_MEASURED_VALUES:
float values[3];
memcpy(values, event.packet->data + 1, sizeof(float) * 3);
emit instance->setMeasuredValues(values[0], values[1], values[2]);
break;
case SET_CPU_USAGE:
emit instance->setCPUUsage(event.packet->data[1]);
break;
case SET_MEMORY_USAGE:
emit instance->setMemoryUsage(event.packet->data[1]);
break;
}
enet_packet_destroy(event.packet);
break;
case ENET_EVENT_TYPE_DISCONNECT:
server = NULL;
emit instance->disconnect();
break;
default:
break;
}
usleep(100);
}
return (void*)0;
}
开发者ID:FlorentRevest,项目名称:Raspcopter,代码行数:58,代码来源:Network.cpp
示例15: enet_host_create
void networkEngine::clientConnect()
{
//gameEngine *gameE = gameEngine::Instance();
boost::shared_ptr<gameEngine> gameE = gameEngine::Instance();
if (!clientEstablishedConnection)
{
client = enet_host_create (NULL /* create a client host */,
4 /* only allow 1 outgoing connection */,
2 /* allow up to 2 channels to be used, 0 and 1*/,
0 /* 56K modem with 56 Kbps downstream bandwidth */,
0 /* 56K modem with 14 Kbps upstream bandwidth */);
if (client == NULL)
{
logMsg("An error occurred while trying to create an ENet client host.");
exit (EXIT_FAILURE);
}
// Old Pre-GUI ipAddress input code
// string ipAddress;
// cout << "IP Address: " << endl;
// cin >> ipAddress;
/* Connect to some.server.net:1234. */
enet_address_set_host (& serverAddress, ipAddress.c_str());
serverAddress.port = 1234;
/* Initiate the connection, allocating the two channels 0 and 1. */
peer = enet_host_connect (client, & serverAddress, 2, 0);
if (peer == NULL)
{
logMsg("No available peers for initiating an ENet connection.");
exit (EXIT_FAILURE);
}
/* Wait up to 5 seconds for the connection attempt to succeed. */
if (enet_host_service (client, & event, 5000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT)
{
logMsg("Connection to " +ipAddress +":1234 succeeded.");
clientEstablishedConnection = true; // Tells other code that this instance is a network client
}
else
{
/* Either the 5 seconds are up or a disconnect event was */
/* received. Reset the peer in the event the 5 seconds */
/* had run out without any significant event. */
enet_peer_reset (peer);
logMsg("Connection to " +ipAddress +":1234 failed.");
}
gameE->setClientRunning(true);
clientEstablishedConnection = true;
}
}
开发者ID:libolt,项目名称:ubc-merge,代码行数:58,代码来源:networkengine.cpp
示例16: cmd_connect
/**
* COMMAND /connect host port
*
* Initiate connection to svceserver.
*/
static int cmd_connect(int argc, dstring** argv) {
ENetAddress address;
char buffer[100];
/* check if client is in correct state to connect */
if (client.state != SVCECLIENT_STATE_DISCONNECTED) {
if (client.state == SVCECLIENT_STATE_CONNECTED) {
fprintf(stderr, "Already connected.\n");
} else if (client.state == SVCECLIENT_STATE_CONNECTING) {
fprintf(stderr, "Already trying to connect.\n");
} else {
fprintf(stderr, "Unknown client state.\n");
}
return 0;
}
if (argc != 3) {
fprintf(stderr, "usage: /connect host port\n");
return 0;
}
/* resolve host */
address.port = atoi(argv[2]->data);
if (enet_address_set_host(&address, argv[1]->data)) {
fprintf(stderr, "Failed to resolve '%s'\n", argv[1]->data);
return 0;
} else {
dcpy(client.server_host_name, argv[1]);
buffer[0] = 0;
enet_address_get_host_ip(&address, buffer, 100);
dcpycs(client.server_host_addr, buffer);
client.server_host_port = address.port;
}
mutex_lock(&client.network_lock);
/* create host */
client.host = enet_host_create(NULL, 1, 2, 0, 0);
if (client.host == NULL) {
mutex_unlock(&client.network_lock);
fprintf(stderr, "An error occurred while trying to create enet host.\n");
return 0;
}
/* initiate connection */
client.client = enet_host_connect(client.host, &address, 2, 0);
if (client.client == NULL) {
enet_host_destroy(client.host);
mutex_unlock(&client.network_lock);
fprintf(stderr, "No available peers to initiate a connection.\n");
return 0;
}
mutex_unlock(&client.network_lock);
client.state = SVCECLIENT_STATE_CONNECTING;
msg_state();
return 0;
}
开发者ID:atheros,项目名称:svc,代码行数:63,代码来源:main.c
示例17: set_ip
bool Client::set_ip(std::string new_ip)
{
if(!_V_is_running and !enet_address_set_host(&_V_address,new_ip.c_str()))
{
_V_ip=new_ip;
return true;
}
return false;
}
开发者ID:chanochambure,项目名称:LexRisLogicHeaders,代码行数:9,代码来源:Client.cpp
示例18: module_start
int module_start (Q5Module* self)
{
int i;
uint32_t gameEngineSrvNo;
ENetAddress address;
if (enet_initialize () != 0)
{
eclogger_msg (LL_ERROR, properties.name, "server", "could not initialize enet");
return FALSE;
}
enet_address_set_host (&address, self->host);
address.port = self->port;
self->server = enet_host_create (&address, 32, 2, 0, 0);
if (!self->server)
{
enet_deinitialize();
eclogger_msg (LL_ERROR, properties.name, "server", "can't start enet server");
return FALSE;
}
eclogger_fmt (LL_DEBUG, properties.name, "server", "listen '%s' on port '%u'", self->host, self->port);
self->threads = eclist_new ();
self->done = FALSE;
for (i = 0; i < 1; i++)
{
EcThread thread = ecthread_new ();
eclist_append(self->threads, thread);
ecthread_start(thread, module_thread_run, self);
}
gameEngineSrvNo = q5core_getModuleId (self->core, "GAME_E");
if (gameEngineSrvNo == 0)
{
eclogger_fmt (LL_WARN, properties.name, "server", "no game engine available");
}
self->entities = gse_create (self->server, gameEngineSrvNo, "Lobo's geiler server");
gse_addRealm (self->entities, "the shire");
ecmessages_add (self->instance->msgid, Q5_DATA_GET, module_callback_get, self);
return TRUE;
}
开发者ID:quom5,项目名称:q5pack_game,代码行数:54,代码来源:q5game_server.c
示例19: createClient
/*
@brief Connect the client to a remote server. createClient() should be called first.
@return True for success.
*/
bool clientConnect(const char* hostName)
{
if (client == nullptr)
{
return false;
}
if (strcmp(hostName, "localhost") == 0)
{
enet_address_set_host(&address, "127.0.0.1");
}
else
{
enet_address_set_host(&address, hostName);
}
address.port = PORT;
peer = enet_host_connect(client, &address, NUM_CHANNELS, CHANNEL_ID);
return (peer != nullptr);
}
开发者ID:phowgego,项目名称:SuperBubble,代码行数:25,代码来源:bubble_net.cpp
示例20: lock
void ClientTransmissionManager::Connect()
{
boost::mutex::scoped_lock lock(this->mHostMutex);
std::stringstream s;
this->mAddress.host = ENET_HOST_ANY;
this->mAddress.port = this->mPort;
if(enet_address_set_host(&this->mAddress, this->mHost.c_str())==0)
{
s << "Resolved hostname.";
this->GetClientSessionManager().Log(s);
if(this->mClient==NULL)
{
this->mClient = enet_host_create(
NULL,
this->mClientLimit,
this->mDownstreamLimit,
this->mUpstreamLimit);
}
if(this->mClient!=NULL)
{
s << "Connected to network.";
this->GetClientSessionManager().Log(s);
this->mPeer = enet_host_connect(this->mClient,&this->mAddress, 5);
if (this->mPeer == NULL)
{
s << "Server not found.";
this->GetClientSessionManager().Log(s);
}
else
{
this->mPeer->data=NULL;
s << "Server found.";
this->GetClientSessionManager().Log(s);
}
}
else
{
s << "Unable to connect to network.";
this->GetClientSessionManager().Log(s);
}
}
else
{
s << "Couldn't resolve hostname.";
this->GetClientSessionManager().Log(s);
}
}
开发者ID:pazuzu156,项目名称:Enigma,代码行数:53,代码来源:ClientTransmissionManager.cpp
注:本文中的enet_address_set_host函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论