anyone interested in Enet?

Everything else that doesn't fall into one of the other PB categories.
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: anyone interested in Enet?

Post by idle »

blueb wrote: Tue Sep 12, 2023 2:20 pm Thanks Idle.
I hadn't noticed this before.

My favorite Flight Simulator allows UDP connections, so I now have my work cut out for me. :mrgreen:
See what you can do with it 🙂
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

Re: anyone interested in Enet?

Post by skinkairewalker »

Do you know how to generate the 32bit version of the libraries?
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: anyone interested in Enet?

Post by idle »

If you use cmake gui and mingw it should be able produce both I will look tomorrow if I can
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

Re: anyone interested in Enet?

Post by skinkairewalker »

awesome :D
thanks by u support...


Regarding the maximum 4096 connections, I read something in the documentation that says the enet connection limit is 4095 connections.
So the solution is to create multithreads to create "extra channels".
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: anyone interested in Enet?

Post by idle »

Yes you have upto 4096 connections per Chanel and tou xan have 256 ot them is what I understood.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

Re: anyone interested in Enet?

Post by skinkairewalker »

strange, I can't understand this Enet, client events don't even work with c++...
Or am I doing it very wrong xD

debugging the enet_host_service function, I have no return other than 0

Code: Select all

Debug enet_host_service(clients(1)\host, @sevent, 0);
and it seems like you can't reduce the disconnection timeout.

client code:

Code: Select all


XIncludeFile "enetpb.pbi"

Define version 

Structure Client
  *host.ENetHost
  *peer.ENetPeer
EndStructure

Procedure CBPacketDestroy(*packet.ENetPacket) 
  Debug  "free " 
EndProcedure   

Procedure CBpacketCreate(*data,dataLength.i,flags.l);
  Debug "create" 
EndProcedure   

OpenConsole() 

Global CB.ENetCallbacks 

cb\packet_destroy = @CBPacketDestroy() 
cb\packet_create = @CBpacketCreate() 

version = enet_linked_version()
Debug ENET_VERSION_GET_MAJOR(version)
Debug ENET_VERSION_GET_MINOR(version)
Debug ENET_VERSION_GET_PATCH(version)  

If enet_initialize_with_callbacks(version,@cb) = 0  
  
  
  Global *server.ENetHost;
  Global sevent.ENetEvent
  Global Dim clients.client(1)     
  Global address.ENetAddress ;
  Global taddress.ENetAddress; 
  
  
  address\host\h = 0 
  address\host\l = 0  
  
  address\port = 7777; /* Bind the server to port 7777. */
  
    enet_address_set_host_new(@address, "127.0.0.1");
    clients(1)\host = enet_host_create(0, 1, 2, 0, 0);
    clients(1)\peer = enet_host_connect(clients(1)\host, @address, 2, 0);
    If (clients(1)\peer = #Null) 
      PrintN("coundlnt connect");
      End
    EndIf 
 
  
  Repeat 

    Debug enet_host_service(clients(1)\host, @sevent, 0);

  ForEver
  

    enet_peer_disconnect_now(clients(1)\peer,0);
    enet_host_destroy(clients(1)\host)         ;

  enet_deinitialize()
  
EndIf    

Input() 

server code:

Code: Select all


XIncludeFile "enetpb.pbi"

  Define version 

Procedure  host_server(server) 
  
  Protected event.ENetEvent 
  Protected *peer.ENetPeer 
  Protected *address.enetaddress 
  
  Static ct1 
  
  While enet_host_service(server, @event, 1) > 0 
    Select event\type 
      Case #ENET_EVENT_TYPE_CONNECT
        PrintN("A new client connected from " + Str(event\peer\address\port));
        
        enet_peer_set_data(event\peer,ct1);
        ct1+1                
      Case #ENET_EVENT_TYPE_RECEIVE
        PrintN("A packet of length " + Str(event\packet\dataLength)) 
        
      Case #ENET_EVENT_TYPE_DISCONNECT
        PrintN("disconnected " + Str(event\peer\Data));
        
        Debug enet_peer_get_data(event\peer)
        
        
      Case #ENET_EVENT_TYPE_DISCONNECT_TIMEOUT
        PrintN("timeout" + Str(event\peer))
        
        
    EndSelect 
  Wend 
EndProcedure 

Procedure CBPacketDestroy(*packet.ENetPacket) 
  Debug  "free " 
EndProcedure   

Procedure CBpacketCreate(*data,dataLength.i,flags.l);
  Debug "create" 
EndProcedure  

OpenConsole("Enet Server 7777") 

Global CB.ENetCallbacks 

cb\packet_destroy = @CBPacketDestroy() 
cb\packet_create = @CBpacketCreate() 

version = enet_linked_version()
Debug ENET_VERSION_GET_MAJOR(version)
Debug ENET_VERSION_GET_MINOR(version)
Debug ENET_VERSION_GET_PATCH(version)  

If enet_initialize_with_callbacks(version,@cb) = 0  
  
  #MAX_CLIENTS = 4095
  
  Global *server.ENetHost;
  Global sevent.ENetEvent
  Global address.ENetAddress ;
  Global taddress.ENetAddress; 
  
  
  address\host\h = 0 
  address\host\l = 0  
  
  address\port = 7777; /* Bind the server to port 7777. */
  
  server = enet_host_create(@address, #MAX_CLIENTS, 2, 0, 0);
  
   If (server = #Null) 
        MessageRequester("","An error occurred While trying To create an ENet server host.\n");
        End
   EndIf

    PrintN("Started a server...\n");
  
  Repeat 
    host_server(server);
    
  ForEver
  
  host_server(server);
  
  enet_host_destroy(server);
  
  enet_deinitialize()
  
  Input() 
  
EndIf     
  
Do you have any idea of what I'm doing wrong (aside from everything xD) ?
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: anyone interested in Enet?

Post by idle »

If I recall the time out is 3 seconds so enet should send a heart beat every 1.5 seconds or something like that. Are you getting a connection.
I'm in bed sick with a fever, so won't be coding for a day or two.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

Re: anyone interested in Enet?

Post by skinkairewalker »

I'm a little worried... only rest, I'll be here if you need anything!
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: anyone interested in Enet?

Post by idle »

I'm through the worst, just resting.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

Re: anyone interested in Enet?

Post by skinkairewalker »

Sending healing vibes your way.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

Re: anyone interested in Enet?

Post by skinkairewalker »

hi, sorry for disappearing..
How are you health?
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: anyone interested in Enet?

Post by idle »

I'm much better thanks.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: anyone interested in Enet?

Post by Kuron »

Very glad to hear it!
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

Re: anyone interested in Enet?

Post by skinkairewalker »

Knowing that you are ok keeps me motivated!!
Could you help me implement enet as a server for my game currently, or are you too busy?
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: anyone interested in Enet?

Post by idle »

In the new year I will have time, at the moment it's chaos.
Post Reply