[ENet-discuss] channel confusion
Brad Monahan
xbradx_00 at hotmail.com
Sun Jan 18 17:49:52 PST 2004
This is the client code I'm using:
// try to connect
ENetAddress address;
ENetEvent event;
ENetPeer *peer;
/* connect to some.server.net:1234 */
enet_address_set_host(&address, gServerIP);
address.port = gServerPort;
/* initiate the connection, allocating the two channels 0 and 1 */
peer = enet_host_connect(gClient, &address, 1);
if(peer == NULL) return 1;
/* wait up to 5 seconds for the connection attempt to succeed */
if(enet_host_service(gClient, &event, 5000) > 0 && event.type ==
ENET_EVENT_TYPE_CONNECT){
SendLoginRequest();
} 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 */
CloseConnection();
enet_deinitialize();
MessageBox(NULL, "Couldn't connect to the server!", "Error", MB_OK);
return 1;
}
Note: The program terminates if it doesn't recieve ENET_EVENT_TYPE_CONNECT.
>From there it calls this function 10 times a second to send key update data
to the server:
// note: unreliable, unsequenced packet over channel 1
void SendClientUpdate()
{
MSG_CLIENTUPDATE_DATA data;
data.type = MSG_CLIENTUPDATE;
data.controls = user[localidx].controls;
data.angle = user[localidx].angle;
data.shotangle = user[localidx].shotangle;
ENetPacket *packet = enet_packet_create(&data, sizeof(data), 0);
enet_peer_send(&gClient->peers[0], 1, packet);
enet_host_flush(gClient);
}
Here's an example of how I send reliable, sequenced packets on channel 0:
void SendLoginRequest()
{
MSG_LOGINREQ_DATA loginreq;
loginreq.type = MSG_LOGINREQ;
loginreq.ver = APP_VERSION;
strncpy(loginreq.name, gUsername, sizeof(loginreq.name));
ENetPacket *packet = enet_packet_create(&loginreq, sizeof(loginreq),
ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(&gClient->peers[0], 0, packet);
enet_host_flush(gClient);
}
-Brad
>From: Lee Salzman <lsalzman at telerama.com>
>Reply-To: Discussion of the ENet library <enet-discuss at cubik.org>
>To: Discussion of the ENet library <enet-discuss at cubik.org>
>Subject: Re: [ENet-discuss] channel confusion
>Date: Sun, 18 Jan 2004 17:55:47 -0500
>
>All the connections in ENet are bidirectional so the server doesn't have
>to do anything more than accept the connection. I would really have to
>see your code to know what's going on.
>
>Lee
>
>On Sun, Jan 18, 2004 at 10:48:49PM +0000, Brad Monahan wrote:
> > Yes I am. That's why I'm thinking it's something with the way I have
>things
> > setup for the channels. Does what I explained seem to be what I should
>be
> > doing then?
> >
> > -Brad
> >
>_______________________________________________
>ENet-discuss mailing list
>ENet-discuss at cubik.org
>http://lists.cubik.org/mailman/listinfo/enet-discuss
_________________________________________________________________
Learn how to choose, serve, and enjoy wine at Wine @ MSN.
http://wine.msn.com/
More information about the ENet-discuss
mailing list