本文整理汇总了C++中enet_host_connect函数的典型用法代码示例。如果您正苦于以下问题:C++ enet_host_connect函数的具体用法?C++ enet_host_connect怎么用?C++ enet_host_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enet_host_connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: enet_address_set_host
void Host::connect(const std::string &hostname, unsigned int port)
{
// set the address of the server to connect to
enet_address_set_host(&mAddress, hostname.c_str());
mAddress.port = port;
// connect to the server
#ifdef ENET_VERSION
mServer = enet_host_connect(mClient, &mAddress, 0, 1);
#else
mServer = enet_host_connect (mClient, &mAddress, 1);
#endif
}
开发者ID:suprafun,项目名称:smalltowns,代码行数:13,代码来源:host.cpp
示例2: 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
示例3: 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
示例4: 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
示例5: 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
示例6: renet_connection_connect
/* The core API functions for a connection:
renet_connection_connect
renet_connection_disconnect
renet_connection_send_packet
renet_connection_send_queued_packets
renet_connection_update
renet_connection_use_compression
renet_connection_online
*/
VALUE renet_connection_connect(VALUE self, VALUE timeout)
{
Connection* connection;
Data_Get_Struct(self, Connection, connection);
VALUE lock = rb_iv_get(self, "@lock");
rb_mutex_lock(lock);
VALUE rv = Qfalse;
if (connection->online == 0)
{
connection->peer = enet_host_connect(connection->host, connection->address, connection->channels, 0);
if (connection->peer == NULL)
{
rb_raise(rb_eStandardError, "Cannot connect to remote host");
}
if (service(self, connection, NUM2UINT(timeout)) > 0 && connection->event->type == ENET_EVENT_TYPE_CONNECT)
{
connection->online = 1;
renet_connection_execute_on_connection(self);
rv = Qtrue;
}
else
{
enet_peer_reset(connection->peer);
}
}
rb_mutex_unlock(lock);
return rv;
}
开发者ID:jvranish,项目名称:rENet,代码行数:42,代码来源:renet_connection.c
示例7: enet_host_create
Network::Network( std::string Server, int Port )
{
localHost = enet_host_create (NULL /* create a client host */,
1 /* only allow 1 outgoing connection */,
1 /* allow up 2 channels to be used, 0 and 1 */,
// 57600 / 8 /* 56K modem with 56 Kbps downstream bandwidth */,
// 14400 / 8 /* 56K modem with 14 Kbps upstream bandwidth */);
0 /* assume any amount of incoming bandwidth */,
0 /* assume any amount of outgoing bandwidth */);
if( localHost == 0 )
{
return;
}
enet_address_set_host( &serverAddress, Server.c_str() );
serverAddress.port = Port;
networkPeer = enet_host_connect( localHost, &serverAddress, 1, 0 );
if( networkPeer == 0 )
{
enet_host_destroy( localHost );
localHost = 0;
return;
}
/* Wait up to 6 seconds for the connection attempt to succeed. */
ENetEvent ev;
if( enet_host_service( localHost, &ev, 6000 ) > 0 && ev.type == ENET_EVENT_TYPE_CONNECT )
{
} else {
enet_peer_reset( networkPeer );
networkPeer = 0;
enet_host_destroy( localHost );
localHost = 0;
return;
}
}
开发者ID:foxblock,项目名称:Pong,代码行数:35,代码来源:network.cpp
示例8: shmup_game_network_connect
void
shmup_game_network_connect(shmup_game *g, int network_type, char *hostname)
{
ENetEvent event;
ENetAddress address;
g->network_type = network_type;
if (g->network_type == SERVER) {
address.host = ENET_HOST_ANY;
address.port = 4000;
fprintf(stderr, "initializing server on port %d...\n", address.port);
g->host = enet_host_create(&address, 4, 2, 0, 0);
} else {
fprintf(stderr, "initializing client...\n");
enet_address_set_host(&address, hostname);
address.port = 4000;
g->host = enet_host_create(NULL, 1, 2, 0, 0);
g->peer = enet_host_connect(g->host, &address, 2, 0);
if (g->peer == NULL) {
fprintf (stderr, "No available peers for initiating an ENet connection.\n");
exit (EXIT_FAILURE);
}
if (enet_host_service (g->host, &event, 5000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT) {
printf("Connection to %s:4000 succeeded.\n", hostname);
g->player[g->num_players].pos = v2(g->window_width/2, g->window_height/2);
g->player[g->num_players].vel = v2zero;
g->player[g->num_players].acc = v2zero;
g->num_players++;
} else {
enet_peer_reset(g->peer);
printf("Connection to %s:4000 failed.\n", hostname);
}
}
}
开发者ID:GunioRobot,项目名称:ShmupEngine,代码行数:35,代码来源:game.c
示例9: enet_lua_host_connect
int enet_lua_api enet_lua_host_connect(lua_State* L) {
ENetHost** udata = luaL_checkudata(L, 1, "_enet.host");
enet_lua_Address_t* address = luaL_checkudata(L, 2, "_enet.address");
enet_uint32 channels = luaL_checkint(L, 3);
enet_host_connect(*udata, &address->address_, channels, 0);
return 0;
}
开发者ID:JoJo2nd,项目名称:Heart,代码行数:7,代码来源:enet_lua.c
示例10: 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
示例11: ERR_FAIL_COND_V
Error NetworkedMultiplayerENet::create_client(const IP_Address& p_ip,int p_port, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth){
ERR_FAIL_COND_V(active,ERR_ALREADY_IN_USE);
host = enet_host_create (NULL /* create a client host */,
1 /* only allow 1 outgoing connection */,
p_max_channels /* allow up 2 channels to be used, 0 and 1 */,
p_in_bandwidth /* 56K modem with 56 Kbps downstream bandwidth */,
p_out_bandwidth /* 56K modem with 14 Kbps upstream bandwidth */);
ERR_FAIL_COND_V(!host,ERR_CANT_CREATE);
ENetAddress address;
address.host=p_ip.host;
address.port=p_port;
/* Initiate the connection, allocating the two channels 0 and 1. */
ENetPeer *peer = enet_host_connect (host, & address, p_max_channels, 0);
if (peer == NULL) {
enet_host_destroy(host);
ERR_FAIL_COND_V(!peer,ERR_CANT_CREATE);
}
//technically safe to ignore the peer or anything else.
connection_status=CONNECTION_CONNECTING;
active=true;
server=false;
return OK;
}
开发者ID:gau-veldt,项目名称:godot,代码行数:33,代码来源:networked_multiplayer_enet.cpp
示例12: 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:bmteam,项目名称:blowmorph,代码行数:25,代码来源:client_host.cpp
示例13: enet_host_connect
void EnetClient::Connect(void)
{
std::cout << "before enet_host_connect" << std::endl;
/* Initiate the connection, allocating the two channels 0 and 1. */
ENetPeer* peer = enet_host_connect(client_ptr_.get(), &server_addr_, 2, 0);
if (peer == NULL)
{
fprintf (stderr, "No available peers for initiating an ENet connection.\n");
exit (EXIT_FAILURE);
}
peer_ptr_.reset(peer, enet_peer_reset);
/* Wait up to 5 seconds for the connection attempt to succeed. */
ENetEvent event;
if (enet_host_service(client_ptr_.get(), &event, 5000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT)
{
puts ("Connection to some.server.net:1234 succeeded.");
}
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. */
peer_ptr_.reset();
puts ("Connection to some.server.net:1234 failed.");
}
}
开发者ID:libinzhangyuan,项目名称:enet_bench_test,代码行数:28,代码来源:enet_client.cpp
示例14: enet_address_set_host
int NetworkManager::connexionToHost(std::string url,int port)
{
/* Connect to some.server.net:1234. */
enet_address_set_host (& address,url.c_str());
address.port = port;
/* Initiate the connection, allocating the two channels 0 and 1. */
peer = enet_host_connect (client, & address, 2, 0);
if (peer == NULL)
{
return 1;
}
/* Wait up to 5 seconds for the connection attempt to succeed. */
if (enet_host_service (client, &eventClient, 5000) > 0 && eventClient.type == ENET_EVENT_TYPE_CONNECT)
{
isConnectedflag = true;
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:respu,项目名称:xsilium-engine,代码行数:30,代码来源:NetworkManager.cpp
示例15: 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
示例16: enet_host_create
bool Manager::createClient(const std::string &host, sf::Uint16 port)
{
_host = enet_host_create(
NULL, // client host
1, // one outgoing connection
1, // one channel
0, // automatic downstream bandwidth
0 // automatic upstream bandwidth
);
if (_host == nullptr)
{
std::cerr << "An error occurred while trying to create an ENet client host." << std::endl;
return false;
}
ENetAddress address;
enet_address_set_host(&address, host.c_str());
address.port = port;
_server = enet_host_connect(_host, &address, 2, 0);
if (_server == nullptr)
{
std::cerr << "No available peers for initiating an ENet connection." << std::endl;
return false;
}
std::cout << "Connecting to host " << host << " on port " << port << "." << std::endl;
return true;
}
开发者ID:antoinusitos,项目名称:Network,代码行数:29,代码来源:Manager.cpp
示例17: enet_host_create
void Network::InitializeClient(const char* ipAdress, const short port, const unsigned int maxDownstream, const unsigned int maxUpstream)
{
std::cout << "Initializing client at port " << port << ".\n";
_host = enet_host_create (NULL, 1, 2, maxDownstream, maxUpstream);
if (_host == NULL)
std::cout << "An error occurred while trying to create an ENet client host.\n";
else
std::cout << "Succesfully created ENet client host.\n";
enet_address_set_host(&_address, ipAdress);
_address.port = port;
_peer = enet_host_connect(_host, &_address, 2, 0);
if (_peer == NULL)
std::cout << "No available peers for initiating an ENet connection.\n";
// If connect send packages
if (enet_host_service(_host, &_event, 1500) > 0 && _event.type == ENET_EVENT_TYPE_CONNECT)
{
_isConnected = true;
printf("Connection to %s:%i succeeded.\n", ipAdress, _address.port);
StartThreads();
}
else
{
enet_peer_reset(_peer);
printf("Connection to %s:%i failed.\n", ipAdress, _address.port);
}
}
开发者ID:gametechnology,项目名称:psi-2013,代码行数:33,代码来源:Network.cpp
示例18: 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
示例19: udpr_connect_out
/**
Connect out from a server socket.
Returns an ENetPeer *, which has not yet connected, or throws if connection fails.
**/
static value udpr_connect_out(value h, value ip, value port, value channels, value timeout) {
ENetAddress address;
ENetEvent event;
ENetHost *host;
ENetPeer *peer;
int to;
val_check_kind(h,k_udprhost);
// checked in address population
//val_check(ip,int);
//val_check(port,int);
val_check(channels,int);
val_check(timeout,int);
to = val_int(timeout);
if(to < 0)
to = 5000;
host = (ENetHost *)val_data(h);
if(populate_address(&address, ip, port) != val_true)
val_throw(alloc_string("address"));
//neko_error();
// Initiate the connection with channels 0..channels-1
peer = enet_host_connect (host, &address, (size_t)val_int(channels));
if (peer == NULL)
//val_throw( alloc_string("Host not found") );
neko_error();
value v = alloc_abstract(k_udprpeer,peer);
return v;
}
开发者ID:Badcreature,项目名称:caffeine-hx,代码行数:36,代码来源:udprsocket.c
示例20: lock
NetworkPeer Network::Connect(const std::string& host, unsigned short port, NetworkCallback* callback)
{
AutoLock<Mutex> lock(m_mutex);
if(!m_host)
return NetworkPeer(0);
if(m_type != CLIENT)
{
std::cout << "Connect operation valid only if type is client" << std::endl;
return NetworkPeer(0);
}
ENetAddress address;
enet_address_set_host(&address, host.c_str());
address.port = port;
ENetPeer* peer = enet_host_connect((ENetHost*)m_host, &address, NETWORK_CHANNEL_COUNT, 0);
if(!peer)
{
std::cout << "Failed to connect to " << host << ":" << port << std::endl;
return NetworkPeer(0);
}
m_networkCallback = callback;
ENetEvent event;
if(enet_host_service((ENetHost*)m_host, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT)
return NetworkPeer(peer);
enet_peer_reset(peer);
std::cout << "Failed to connect to " << host << ":" << port << std::endl;
return NetworkPeer(0);
}
开发者ID:voidah,项目名称:tak,代码行数:35,代码来源:network.cpp
注:本文中的enet_host_connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论