本文整理汇总了C++中enet_packet_create函数的典型用法代码示例。如果您正苦于以下问题:C++ enet_packet_create函数的具体用法?C++ enet_packet_create怎么用?C++ enet_packet_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enet_packet_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: renet_connection_send_packet
VALUE renet_connection_send_packet(VALUE self, VALUE data, VALUE flag, VALUE channel)
{
Connection* connection;
Data_Get_Struct(self, Connection, connection);
VALUE lock = rb_iv_get(self, "@lock");
rb_mutex_lock(lock);
Check_Type(data, T_STRING);
char* cdata = StringValuePtr(data);
ENetPacket* packet;
if (connection->online != 0)
{
if (flag == Qtrue)
{
packet = enet_packet_create(cdata, RSTRING_LEN(data) + 1, ENET_PACKET_FLAG_RELIABLE);
}
else
{
packet = enet_packet_create(cdata, RSTRING_LEN(data) + 1, 0);
}
enet_peer_send(connection->peer, NUM2UINT(channel), packet);
}
rb_mutex_unlock(lock);
return Qnil;
}
开发者ID:jvranish,项目名称:rENet,代码行数:26,代码来源:renet_connection.c
示例2: sendmap
void sendmap(char *mapname)
{
if(*mapname) save_world(mapname);
changemap(mapname);
mapname = getclientmap();
int mapsize;
uchar *mapdata = readmap(mapname, &mapsize);
if(!mapdata) return;
ENetPacket *packet = enet_packet_create(NULL, MAXTRANS + mapsize, ENET_PACKET_FLAG_RELIABLE);
uchar *start = packet->data;
uchar *p = start+2;
putint(p, SV_SENDMAP);
sendstring(mapname, p);
putint(p, mapsize);
if(65535 - (p - start) < mapsize)
{
conoutf("map %s is too large to send", mapname);
free(mapdata);
enet_packet_destroy(packet);
return;
};
memcpy(p, mapdata, mapsize);
p += mapsize;
free(mapdata);
*(ushort *)start = ENET_HOST_TO_NET_16(p-start);
enet_packet_resize(packet, p-start);
sendpackettoserv(packet);
conoutf("sending map %s to server...", mapname);
sprintf_sd(msg)("[map %s uploaded to server, \"getmap\" to receive it]", mapname);
toserver(msg);
}
开发者ID:lazharous,项目名称:Lazarus,代码行数:31,代码来源:clientextras.cpp
示例3: GetDriverName
void NetClient::SendReadyToStartPacket()
{
std::string strDName = GetDriverName();
GfLogTrace("Sending ready to start packet\n");
PackedBuffer msg;
try
{
msg.pack_ubyte(CLIENTREADYTOSTART_PACKET);
msg.pack_stdstring(strDName);
}
// catch (PackedBufferException &e)
catch (PackedBufferException)
{
GfLogFatal("SendReadyToStartPacket: packed buffer error\n");
}
GfLogTrace("SendReadyToStartPacket: packed data length=%d\n",
msg.length());
ENetPacket *pPacket = enet_packet_create (msg.buffer(),
msg.length(),
ENET_PACKET_FLAG_RELIABLE);
if (enet_peer_send (m_pServer, RELIABLECHANNEL, pPacket))
GfLogError("SendReadyToStartPacket : enet_peer_send failed\n");
}
开发者ID:xinderuila1,项目名称:speed-dream,代码行数:28,代码来源:client.cpp
示例4: handle_input_command
/**
* Handle input command.
*
* This function should return 0, even if the command failed.
* Return of != 0 means the event loop will quit.
*/
static int handle_input_command(const dstring* string) {
dstrlist* list;
dstring** argv;
unsigned int argc;
int error;
ENetPacket* packet;
if (string->len == 0) {
/* empty command */
return 0;
} else if (string->data[0] == '/') {
/* local command */
/* parse the command */
list = dstrlex_parse(string, &error);
if (list == NULL) {
fprintf(stderr, "Failed to parse command string '%s': %s\n", string->data, dstrlex_errstr(error));
return 0;
}
/* convert list to vector */
argc = list->size;
argv = dlist_tovector(list);
dlist_free(list);
/* select command to execute */
if (dcmpcs(argv[0], "/connect") == 0) {
error = cmd_connect(argc, argv);
} else if (dcmpcs(argv[0], "/disconnect") == 0) {
error = cmd_disconnect(argc, argv);
} else if (dcmpcs(argv[0], "/quit") == 0) {
error = cmd_quit(argc, argv);
} else if (dcmpcs(argv[0], "/mute") == 0) {
error = cmd_mute(argc, argv);
} else if (dcmpcs(argv[0], "/deafen") == 0) {
error = cmd_deafen(argc, argv);
} else {
fprintf(stderr, "Unknown command '%s'\n", argv[0]->data);
error = 0;
}
dvec_free(argv);
return error;
} else if (client.state == SVCECLIENT_STATE_CONNECTED) {
/* send to server if connected */
mutex_lock(&client.network_lock);
packet = enet_packet_create(string->data, string->len, ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(client.client, 0, packet);
mutex_unlock(&client.network_lock);
} else if (client.state == SVCECLIENT_STATE_CONNECTING) {
/* server command but still connecting */
fprintf(stderr, "Can't send command to server, still connecting.\n");
} else {
/* server command but not connected */
fprintf(stderr, "Can't send command to server, not connected.\n");
}
return 0;
}
开发者ID:atheros,项目名称:svc,代码行数:66,代码来源:main.c
示例5: enet_packet_create
void Connection::send_packet_unreliable(void *data,int ID){
ENetPacket *packet = enet_packet_create (data, sizeof(data), ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT);
if(!client)
enet_peer_send (&connS->peers[ID], 0, packet);
else
enet_peer_send(peer,0,packet);
}
开发者ID:killertux,项目名称:Troll-Killers,代码行数:7,代码来源:Connection.cpp
示例6: while
void GDNetHost::send_messages() {
while (!_message_queue.is_empty()) {
GDNetMessage* message = _message_queue.pop();
int flags = 0;
switch (message->get_type()) {
case GDNetMessage::UNSEQUENCED:
flags |= ENET_PACKET_FLAG_UNSEQUENCED;
break;
case GDNetMessage::RELIABLE:
flags |= ENET_PACKET_FLAG_RELIABLE;
break;
default:
break;
}
ByteArray::Read r = message->get_packet().read();
ENetPacket * enet_packet = enet_packet_create(r.ptr(), message->get_packet().size(), flags);
if (enet_packet != NULL) {
if (message->is_broadcast()) {
enet_host_broadcast(_host, message->get_channel_id(), enet_packet);
} else {
enet_peer_send(&_host->peers[message->get_peer_id()], message->get_channel_id(), enet_packet);
}
}
memdelete(message);
}
}
开发者ID:jrimclean,项目名称:gdnet,代码行数:33,代码来源:gdnet_host.cpp
示例7: enet_packet_create
void ENetServer::broadcastMessage(DeliveryType type, Message::Shared msg) const
{
if (numClients() == 0) {
// no clients to broadcast to
return;
}
uint32_t channel = 0;
uint32_t flags = 0;
if (type == DeliveryType::RELIABLE) {
channel = RELIABLE_CHANNEL;
flags = ENET_PACKET_FLAG_RELIABLE;
} else {
channel = UNRELIABLE_CHANNEL;
flags = ENET_PACKET_FLAG_UNSEQUENCED;
}
// get bytes
auto data = msg->serialize();
// create the packet
ENetPacket* p = enet_packet_create(
&data[0],
data.size(),
flags);
// send the packet to the peer
enet_host_broadcast(host_, channel, p);
// flush / send the packet queue
enet_host_flush(host_);
}
开发者ID:kbirk,项目名称:enet-example,代码行数:31,代码来源:ENetServer.cpp
示例8: qDebug
void Tunnelc::onENetPeerConnected(ENetHost *enhost, ENetPeer *enpeer, quint32 data)
{
qDebug()<<enhost<<enpeer<<data;
// ToxTunChannel *chan = this->m_enpeer_chans[enpeer];
// ToxTunChannel *chan = (ToxTunChannel*)enpeer->toxchan;
ToxTunChannel *chan = peerLastChan(enpeer);
// enet_peer_ping_interval()
// enet_peer_ping(
enet_peer_timeout(enpeer, UINT32_MAX/*ENET_PEER_TIMEOUT_LIMIT * 0xfffff*/,
UINT32_MAX/*ENET_PEER_TIMEOUT_MINIMUM * 0xffff*/,
UINT32_MAX/*ENET_PEER_TIMEOUT_MAXIMUM * 0xffff*/);
enet_peer_ping_interval(enpeer, UINT32_MAX/*ENET_PEER_PING_INTERVAL * 0xfffff*/);
emit chan->m_sock->readyRead();
if (false) {
ENetPacket *packet = enet_packet_create("hehehe123", 10, ENET_PACKET_FLAG_RELIABLE);
enet_packet_resize(packet, 13);
strcpy((char*)&packet->data[9], "foo");
uint8_t chanid = 0;
// enet_peer_send(enpeer, chanid, packet);
m_enpoll->sendPacket(enpeer, chanid, packet);
}
}
开发者ID:kitech,项目名称:toxsh,代码行数:26,代码来源:tunnelc.cpp
示例9: main
int main (int argc, char * const argv[]) {
if(enet_initialize() != 0)
{
printf("An error occurred while initializing ENet.\n");
}
ENetAddress address;
ENetHost* server;
address.host = ENET_HOST_ANY;
address.port = 9050;
// up to 32 clients with unlimited bandwidth
server = enet_host_create(&address, 32, 0, 0);
if(server == NULL)
{
printf("An error occurred while trying to create an ENet server host.\n");
}
int clients = 0;
// server main loop
while(true)
{
ENetEvent event;
while(enet_host_service(server, &event, 1000) > 0)
{
switch(event.type)
{
case ENET_EVENT_TYPE_CONNECT:
printf ("A new client connected from %x:%u.\n",
event.peer -> address.host,
event.peer -> address.port);
clients++;
break;
case ENET_EVENT_TYPE_RECEIVE:
printf ("A packet of length %u containing %s was received.\n",
event.packet->dataLength,
event.packet->data);
ENetPacket* packet = enet_packet_create(event.packet->data, event.packet->dataLength, ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast(server, 0, packet);
enet_host_flush(server);
enet_packet_destroy(event.packet);
break;
case ENET_EVENT_TYPE_DISCONNECT:
printf("Client disconnected.\n");
event.peer->data = NULL;
}
}
}
return 0;
}
开发者ID:simudream,项目名称:oolong,代码行数:60,代码来源:main.cpp
示例10: sizeof
void NetManager::sendServerPacket()
{
FAWorld::World& world = *FAWorld::World::get();
size_t bytesPerClient = world.getCurrentPlayer()->getSize() + sizeof(uint32_t); // the uint is for player id
size_t packetSize = sizeof(ServerPacketHeader) + bytesPerClient*(mClients.size() +1); // +1 for the local player
ENetPacket* packet = enet_packet_create(NULL, packetSize, 0);
size_t position = 0;
// write header
ServerPacketHeader header;
header.numPlayers = mClients.size() + 1;
header.tick = mTick;
writeToPacket(packet, position, header);
// write server player
writeToPacket<uint32_t>(packet, position, SERVER_PLAYER_ID);
position = world.getCurrentPlayer()->writeTo(packet, position);
// write all clients
for(size_t i = 0; i < mClients.size(); i++)
{
writeToPacket<uint32_t>(packet, position, mClients[i]->connectID);
position = world.getPlayer(mClients[i]->connectID)->writeTo(packet, position);
}
enet_host_broadcast(mHost, 0, packet);
}
开发者ID:titusmaximus,项目名称:freeablo,代码行数:29,代码来源:netmanager.cpp
示例11: enet_packet_create
void CNetManager::sendOutPacket(SOutPacket& outpacket)
{
ENetPacket* packet = enet_packet_create((char*)outpacket.getData(), outpacket.getSize(),
ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast(host, 0, packet);
}
开发者ID:tecan,项目名称:LunaLibs,代码行数:7,代码来源:CNetManager.cpp
示例12: send_welcome
void send_welcome(int n) {
ENetPacket * packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
uchar *start = packet->data;
uchar *p = start + 2;
putint(p, SV_INITS2C);
putint(p, n);
putint(p, PROTOCOL_VERSION);
putint(p, smapname[0]);
sendIString(serverpassword, p);
putint(p, clients.size() > maxclients);
if (smapname[0]) {
putint(p, SV_MAPCHANGE);
sendIString(smapname, p);
putint(p, mode);
putint(p, SV_ITEMLIST);
for (int i = 0; i < sents.size(); i++) {
if (sents[i].spawned)
putint(p, i);
}
putint(p, -1);
};
*(ushort *) start = ENET_HOST_TO_NET_16(p - start);
enet_packet_resize(packet, p - start);
send(n, packet);
}
开发者ID:mailgyc,项目名称:cube,代码行数:25,代码来源:server.cpp
示例13: enet_packet_create
bool Game::send(const Packet & packet, ENetPeer * peer)
{
ENetPacket * enetPacket = enet_packet_create(packet.getData(), packet.getDataSize(), ENET_PACKET_FLAG_RELIABLE);
if (!enetPacket)
return false;
return enet_peer_send(peer, 0, enetPacket) == 0;
}
开发者ID:kiwon0905,项目名称:Residents-vs-Aliens,代码行数:7,代码来源:Game.cpp
示例14: ThreadSend
void* ThreadSend() {
while(1) {
CCLOG("wait mutex to send");
mutexMapPlay.lock();
// pthread_mutex_lock(&mutexMapPlay);
mapLayerToString(playLayer, packetBuffer);
// strcpy(packetBuffer, "0000000030000003000000000000000000000010000000000\1");
ENetPacket * packet = enet_packet_create (packetBuffer,
150,
ENET_PACKET_FLAG_RELIABLE);
CCLOG(packet->data);
/* Send the packet to the peer over channel id 0. */
/* One could also broadcast the packet by */
/* enet_host_broadcast (host, 0, packet); */
enet_peer_send (peer, 0, packet);
/* One could just use enet_host_service() instead. */
enet_host_flush (server);
CCLOG("finish send packet");
}
enet_peer_disconnect (peer, 0);
enet_peer_reset (peer);
CCLOG("exit thread send");
return NULL;
}
开发者ID:Group2,项目名称:The-New-Lines,代码行数:26,代码来源:CurlTest.cpp
示例15: qDebug
void Tunneld::onTcpDisconnected()
{
qDebug()<<""<<enet_host_used_peer_size(m_ensrv)<<m_sock_chans.count()<<m_conid_chans.count();
QTcpSocket *sock = (QTcpSocket*)(sender());
ToxTunChannel *chan = this->m_sock_chans[sock];
// qDebug()<<chan<<chan->m_enpeer->state;
chan->sock_closed = true;
chan->sock_close_time = QDateTime::currentDateTime();
// 防止对方没有收完,暂时还不能关闭连接。
// enet_peer_disconnect_later(chan->m_enpeer, qrand());
if (true) {
QByteArray ba = "SRVFIN";
ENetPacket *packet = enet_packet_create(ba.data(), ba.length(), ENET_PACKET_FLAG_RELIABLE);
// enet_packet_resize(packet, 13);
// strcpy((char*)&packet->data[9], "foo");
uint8_t chanid = 1;
ENetPeer *enpeer = chan->m_enpeer;
// enet_peer_send(enpeer, chanid, packet);
m_enpoll->sendPacket(enpeer, chanid, packet);
}
this->promiseChannelCleanup(chan);
}
开发者ID:kitech,项目名称:toxsh,代码行数:28,代码来源:tunneld.cpp
示例16: rAssert
ENetPacket* ListenServerNetMode::createSpawnPacket(Object* object)
{
rAssert(object);
std::string prototype;
if(object->getPrototype())
{
prototype = object->getPrototype()->getFilePath();
}
else
{
prototype.append(".");
prototype.append(object->getObjectClassName());
}
SNetSpawnObject data;
data.type = NET_PT_SPAWN_OBJECT;
data.objectNetId = object->xiGetNetId();
data.pathSize = prototype.length();
memcpy(m_riBuffer, &data, sizeof(SNetSpawnObject));
memcpy((m_riBuffer + sizeof(SNetSpawnObject)), prototype.data(), prototype.length());
ENetPacket* packet = enet_packet_create(m_riBuffer, sizeof(SNetSpawnObject) + prototype.length(), ENET_PACKET_FLAG_RELIABLE);
return packet;
}
开发者ID:creepydragon,项目名称:r2,代码行数:26,代码来源:ListenServerNetMode.cpp
示例17: while
void Tunneld::onTcpReadyRead()
{
QTcpSocket *sock = (QTcpSocket*)sender();
ToxTunChannel *chan = this->m_sock_chans[sock];
if (chan->m_enpeer->state == ENET_PEER_STATE_CONNECTED) {
while (sock->bytesAvailable() > 0) {
// QByteArray ba = sock->readAll();
QByteArray ba = sock->read(567);
if (ba.length() >= 1371) {
qDebug()<<"too long data packet.";
}
ENetPacket *packet = enet_packet_create(ba.data(), ba.length(), ENET_PACKET_FLAG_RELIABLE);
// enet_packet_resize(packet, 13);
// strcpy((char*)&packet->data[9], "foo");
uint8_t chanid = 0;
ENetPeer *enpeer = chan->m_enpeer;
// enet_peer_send(enpeer, chanid, packet);
m_enpoll->sendPacket(enpeer, chanid, packet);
}
}
}
开发者ID:kitech,项目名称:toxsh,代码行数:26,代码来源:tunneld.cpp
示例18: getClient
void ENetServer::sendMessage(uint32_t id, DeliveryType type, Message::Shared msg) const
{
auto client = getClient(id);
if (!client) {
// no client to send to
LOG_WARN("No connected client with id: " << id);
return;
}
uint32_t channel = 0;
uint32_t flags = 0;
if (type == DeliveryType::RELIABLE) {
channel = RELIABLE_CHANNEL;
flags = ENET_PACKET_FLAG_RELIABLE;
} else {
channel = UNRELIABLE_CHANNEL;
flags = ENET_PACKET_FLAG_UNSEQUENCED;
}
// get bytes
auto data = msg->serialize();
// create the packet
ENetPacket* p = enet_packet_create(
&data[0],
data.size(),
flags);
// send the packet to the peer
enet_peer_send(client, channel, p);
// flush / send the packet queue
enet_host_flush(host_);
}
开发者ID:kbirk,项目名称:enet-example,代码行数:31,代码来源:ENetServer.cpp
示例19: udpr_write
/**
udpr_write : ENetPeer-> data:string -> Channel->Reliable:Bool->void
Send a full string [data]
**/
static value udpr_write(value p, value data, value chan, value reliable)
{
ENetPeer *peer;
ENetPacket *packet;
int c;
val_check_kind(p,k_udprpeer);
val_check(data,string);
val_check(chan,int);
val_check(reliable,bool);
c = val_int(chan);
peer = (ENetPeer *)val_data(p);
#ifdef ENET_DEBUG_FULL
fprintf(stderr, "udpr_write: Writing packet '%s' to peer %x on channel %d\n", val_string(data), peer, c);
fprintf(stderr, "peer state: %d peer channels: %d\n", peer -> state, peer->channelCount);
#endif
if(peer == NULL || c < 0 || c > 255)
neko_error();
packet = enet_packet_create(
val_string(data),
val_strlen(data),
val_bool(reliable) ? ENET_PACKET_FLAG_RELIABLE : 0);
if(enet_peer_send(peer, c, packet)) {
#ifdef ENET_DEBUG
fprintf(stderr, "ERROR: udpr_write: enet_peer_send error\n");
fprintf(stderr, "peer state: %d peer channels: %d\n", peer -> state, peer->channelCount);
#endif
neko_error();
}
return val_true;
}
开发者ID:Badcreature,项目名称:caffeine-hx,代码行数:36,代码来源:udprsocket.c
示例20: send_callback
/**
* audio callback.
*/
void send_callback(svc_network_packet_t* packet){
enet_uint32 src;
ENetPacket* epacket;
unsigned char* data;
/* get ID */
mutex_lock(&client.network_lock);
src = client.my_id;
/* this client didn't get it's ID yet (this also handles connection state as my_id==-1 if not connected)
* or is muted. */
if (src == -1 || client.muted) {
mutex_unlock(&client.network_lock);
return;
}
/* allocate data */
data = (unsigned char*)malloc(packet->data_len+10);
*(enet_uint32*)data = ENET_HOST_TO_NET_32(src);
*(enet_uint32*)(data + 4) = ENET_HOST_TO_NET_32(packet->data_len+2);
*(enet_uint16*)(data + 8) = ENET_HOST_TO_NET_16(packet->time);
/* copy audio data */
memcpy(data + 10, packet->data, packet->data_len);
epacket = enet_packet_create(data, packet->data_len + 10, ENET_PACKET_FLAG_UNSEQUENCED);
enet_peer_send(client.client, 1, epacket);
enet_host_flush(client.host);
mutex_unlock(&client.network_lock);
free(data);
}
开发者ID:atheros,项目名称:svc,代码行数:36,代码来源:main.c
注:本文中的enet_packet_create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论