[ENet-discuss] ENet - desconnection in 30 seconds after connection.
Nuno Silva
little.coding.fox at gmail.com
Fri Nov 5 08:31:18 PDT 2010
Well, it depends, if you're not getting any events it's normal that
enet_host_service blocks for 15ms. Are you trying to say that ENet is
"slow"? Because 7.5ms of lag between checking events and sending a message
isnt really slow. ENet has been used in various projects with great success,
surely those 7.5ms arent time critical for your app? If they are, then you
might consider getting a different network library.
2010/11/5 Вячеслав Блинников <slavmfm at gmail.com>
> I reduced the timeout (third param of "enet_host_service()") to 15
> milliseconds and connection became faster - so it proofs that actually
> message (using "enet_peer_send()") will be sent with lag which vary
> between 0 and 15 milliseconds - we have 7,5 milliseconds lag! And it's
> just in sending.
>
> 5 ноября 2010 г. 18:17 пользователь Вячеслав Блинников
> <slavmfm at gmail.com> написал:
> > That is strange because previous advice helped me - everything what
> > was needed is to call "enet_host_service()" in separate thread (I
> > tried to call it between "getchar()" calls but there still was
> > disconnections).
> > But I definetly feel some lags. Sometimes lags are obvious but
> > sometimes it looks like there are no of them - I think it's depends on
> > when how close to "enet_host_service()"'s time interval
> > "enet_peer_send()" will be called.
> >
> > 2010/11/5 Nicholas J Ingrassellino <nick at lifebloodnetworks.com>:
> >> The same thing happens to me if the client does nothing (no events to
> send,
> >> ect) even when calling enet_host_service() on a regular basis. I just
> added
> >> an unreliable "ping packet" every once in a while which solved it.
> >>
> >> ________________________________
> >>
> >> Nicholas J Ingrassellino
> >> LifebloodNetworks.com || nick at lifebloodnetworks.com
> >>
> >> "The idea that I can be presented with a problem, set out to logically
> solve
> >> it with the tools at hand, and wind up with a program that could not be
> >> legally used because someone else followed the same logical steps some
> years
> >> ago and filed for a patent on it is horrifying."
> >> - John Carmack on software patents
> >>
> >> On 11/05/2010 10:10 AM, Nuno Silva wrote:
> >>
> >> Hey there.
> >> On your while(true) on the client you must also call enet_host_service
> in
> >> order for the client to keep its connection alive.
> >>
> >> 2010/11/5 Вячеслав Блинников <slavmfm at gmail.com>
> >>>
> >>> Hello!
> >>>
> >>> I wrote the base client accordingly the tutorial and the client which
> >>> read inputting through console characters and send it to the server.
> >>> Everything is fine but just first 30 seconds - then happen the
> >>> disconnection (message "Client information disconnected" shown).
> >>> What is wrong with my code?
> >>>
> >>>
> >>>
> >>> Server code:
> >>>
> >>> #include <cstdio>
> >>> #include "enet\enet.h"
> >>> int main(int argc, int** argv)
> >>> {
> >>> if (enet_initialize () != 0)
> >>> {
> >>> printf ("An error occurred while initializing ENet.\n");
> >>> goto END;
> >>> }
> >>> ENetAddress address;
> >>> address.host = ENET_HOST_ANY;
> >>> address.port = 1234;
> >>> ENetHost* server = enet_host_create ( & address, 32, 2, 0, 0);
> >>> if (server == NULL)
> >>> {
> >>> printf("An error occurred while trying to create an ENet
> >>> client host.\n");
> >>> goto END;
> >>> }
> >>> ENetEvent event;
> >>> WAIT_FOR_AN_EVENT:
> >>> enet_host_service(server, &event, 5);
> >>> 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);
> >>> event.peer -> data = "Client information";
> >>> break;
> >>>
> >>> case ENET_EVENT_TYPE_RECEIVE:
> >>> printf ("A packet of length %u was received from %s on
> >>> channel %u.
> >>> Containings:\n %s", event.packet -> dataLength, event.peer -> data,
> >>> event.channelID, event.packet -> data);
> >>> enet_packet_destroy (event.packet);
> >>> break;
> >>>
> >>> case ENET_EVENT_TYPE_DISCONNECT:
> >>> printf ("%s disconected.\n", event.peer -> data);
> >>> event.peer -> data = NULL;
> >>> break;
> >>>
> >>> case ENET_EVENT_TYPE_NONE:
> >>> break;
> >>> }
> >>> goto WAIT_FOR_AN_EVENT;
> >>>
> >>> printf("host halted.\n");
> >>>
> >>> END:
> >>> getchar();
> >>> return 0;
> >>> }
> >>>
> >>>
> >>>
> >>> Client code:
> >>>
> >>> #include <cstdio>
> >>> #include "enet\enet.h"
> >>> #include <vector>
> >>> int main(int argc, int** argv)
> >>> {
> >>> //where reading console data will be stored:
> >>> std::vector<char> buffer;
> >>>
> >>> if (enet_initialize () != 0)
> >>> {
> >>> printf ("An error occurred while initializing ENet.\n");
> >>> goto END;
> >>> }
> >>> ENetHost* client = enet_host_create ( NULL, 1, 2, 57600 /
> 8,
> >>> 14400 / 8);
> >>> if(client == 0l)
> >>> {
> >>> printf("An error occurred while trying to create an ENet
> >>> server host.\n");
> >>> goto END;
> >>> }
> >>> ENetAddress address;
> >>> enet_address_set_host(&address, "localhost");
> >>> address.port = 1234;
> >>>
> >>> ENetPeer* peer = enet_host_connect(client, &address, 2, 0);
> >>> if(peer == 0l)
> >>> {
> >>> printf("No available peers for initiating an ENet
> >>> connection.\n");
> >>> goto END;
> >>> }
> >>>
> >>> ENetEvent event;
> >>> if (enet_host_service (client, & event, 5000) > 0 && event.type
> ==
> >>> ENET_EVENT_TYPE_CONNECT)
> >>> {
> >>> puts ("Connection to localhost:1234 succeeded.");
> >>> }
> >>> else
> >>> {
> >>> enet_peer_reset (peer);
> >>>
> >>> puts ("Connection to localhost:1234 failed.");
> >>> goto END;
> >>> }
> >>>
> >>> printf("Input some data which will be sent to server...\n");
> >>>
> >>> INPUT_DATA:
> >>> buffer.clear();
> >>> while(true)
> >>> {
> >>> char character = getchar();
> >>> buffer.push_back(character);
> >>> if(character == '\n')
> >>> {
> >>> break;
> >>> }
> >>> }
> >>> buffer.push_back('\0');
> >>>
> >>> ENetPacket * packet = enet_packet_create(&buffer[0],
> buffer.size(),
> >>> ENET_PACKET_FLAG_RELIABLE);
> >>> enet_peer_send (peer, 0, packet);
> >>> enet_host_flush(client);
> >>> goto INPUT_DATA;
> >>>
> >>> END:
> >>> getchar();
> >>>
> >>> return 0;
> >>> }
> >>> _______________________________________________
> >>> ENet-discuss mailing list
> >>> ENet-discuss at cubik.org
> >>> http://lists.cubik.org/mailman/listinfo/enet-discuss
> >>
> >>
> >> _______________________________________________
> >> ENet-discuss mailing list
> >> ENet-discuss at cubik.org
> >> http://lists.cubik.org/mailman/listinfo/enet-discuss
> >>
> >> _______________________________________________
> >> ENet-discuss mailing list
> >> ENet-discuss at cubik.org
> >> http://lists.cubik.org/mailman/listinfo/enet-discuss
> >>
> >>
> >
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20101105/d057babe/attachment.html>
More information about the ENet-discuss
mailing list