[ENet-discuss] ENet - desconnection in 30 seconds after connection.
Nicholas J Ingrassellino
nick at lifebloodnetworks.com
Fri Nov 5 08:58:14 PDT 2010
/enet_peer_ping()/! I had no idea that existed.
This is making me want to create better documentation for ENet even
more. The tutorial is nice but not enough alone.
------------------------------------------------------------------------
Nicholas J Ingrassellino
LifebloodNetworks.com <http://www.lifebloodnetworks.com/> ||
nick at lifebloodnetworks.com <mailto: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 11:06 AM, Nuno Silva wrote:
> Or you could just call enet_ping :D
> At least AFAIR there's a function named like that.
>
> On Fri, Nov 5, 2010 at 2:58 PM, Nicholas J Ingrassellino
> <nick at lifebloodnetworks.com <mailto:nick at lifebloodnetworks.com>> wrote:
>
> 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 <http://www.lifebloodnetworks.com/> ||
> nick at lifebloodnetworks.com <mailto: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
>> <mailto: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 <mailto:ENet-discuss at cubik.org>
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
>>
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org <mailto:ENet-discuss at cubik.org>
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org <mailto: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/0bc33d44/attachment.html>
More information about the ENet-discuss
mailing list