Jump to content

  • Log In with Google      Sign In   
  • Create Account


hsine

Member Since 09 Jan 2013
Offline Last Active Private

Topics I've Started

Raknet: what will happen if connecting to a connected peer

05 March 2013 - 04:19 AM


 
 
connect for 1th time

C--------------------------------------------<CONNECTED>----------------------------------->S:
got                                                                                                                                 got
[ID_CONNECTION_REQUEST_ACCEPTED]                                                           [ID_NEW_INCOMING_CONNECTION]

ok , c-to-s connection is established!
what will happend if i connect from C to S again ?
m_Client->Connect(..........);
what message id will get in C and S site ? and what will cause this messageID to be repied : ID_ALREADY_CONNECTED:

how to receive broadcast and reply to broadcast sender by using enet

11 January 2013 - 08:33 PM

once a client send broadcast to all host server in a same subnet, how can servers recevice the broadcast infomation and make reply to the client 
who has send the broadcast?
 
client :
----------------------------------------------------------------

 

void scan_servers_by_send_broadcast()
{
ENETAddress address;


    address.host = ENET_HOST_BROADCAST;
    address.port = BROADCAST_PORT


ENETSocket socket = ENET_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
ENET_socket_set_option(socket,ENET_SOCKOPT_NONBLOCK,1);
ENET_socket_set_option(socket,ENET_SOCKOPT_BROADCAST,1);


ENET_socket_send(socket,address,&broadcast_buf,1);
ENET_socket_destroy(socket);
}

 

 
servers:
-------------------------------------------------------------
[Q: How can a server received broadcast information and tell client its ip address ?]
 

 

ENETSocket socket = ENET_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
ENET_socket_set_option(socket,ENET_SOCKOPT_NONBLOCK,1);
ENET_socket_set_option(socket,ENET_SOCKOPT_REUSEADDR,1);
ENET_socket_set_option(socket,ENET_SOCKOPT_BROADCAST,1);


ENETAddress serv_addr;
    serv_addr.host=ENET_HOST_ANY;
    serv_addr.port=BROADCAST_PORT;      // IS THIS RIGHT?
ENET_socket_bind(socket,&serv_addr);
...........

 

I DON'T KNOW WHAT SHOULD DO AFTER BINDING,,,,,  HELP ME PLEASE ,THANKS/...
 
any more, does BROADCAST_PORT shold be different from the SERVER_MAIN_SERVICE_PORT ?
 

How can enet listening more than 1 port at same time?

10 January 2013 - 01:27 PM

in my project requires to listening about 3 port at same time for difference busniess , but for enet demo code:

once i established a server by

ENetHost* create server(int port){
ENetAddress* addr;
addr->host=.....
addr->port=port;

server=p2udp_host_create(&serv_addr,MAX_CLIENT_LINKS,MAX_CHANNEL_SET,0,0);

。。。。

return server;
}

than i call this function 3 times so i got about 3 server instance with 3 different ports, but only 1 port can handle events which was first made.

 

so the question is how can i handle the message events for all of 3 ports because event handling  procedure is in located a while loop just like:

 

 

 

service_event_handle(ENetHost* server)
{
  ENETEVENET event;
  while(1){
    switch(.....){
    }
 }

}

when i pass the params server1 create by , it just traped in loop without ending conditions 

 

i wonder how can i  jump the loop do handle evnets for another 2 port

 

,


does enet can send and receive struct?

09 January 2013 - 09:57 AM

client code like this :

 

</p><div>   typedef struct _T{</div>
<div>        int id;</div>
<div>        char* testdata;</div>
<div>    }T, *PT;</div>
<div>    PT pt;</div>
<div>    memset(pt,0,sizeof(&pt));</div>
<div>    pt->id=1;</div>
<div>    pt->testdata="test datya";</div>
<div>    char pack[128];</div>
<div>    memcpy(&pack,pt,sizeof(&pt));    ////////////////////////////  pack got nothing???</div>
<div>    ENetPacket *packet=enet_packet_create((const void*)&pack,128,ENET_PACKET_FLAG_RELIABLE);</div>
<div>    if(NULL == packet){</div>
<div>        fprintf(stderr,"create packet with error\n");</div>
<div>        exit(EXIT_FAILURE);</div>
<div>    }</div>
<div> </div>
<div>    enet_peer_send(peer,0,packet);</div>
<div> </div>
<div>    enet_host_flush(client);</div>
<div>
 
but the server can';t  get anything ...? what wrong with it?

why i can't send or receive anything ....

09 January 2013 - 07:51 AM

post my code first 
please help me to point out where is wrong?
 
client code :
</div>
<div>int send_to_peer(ENETHost* client, ENETPeer *peer)</div>
<div>{</div>
<div>   i</div>
<div>    ENETPacket *packet=ENET_packet_create(NULL,128,ENET_PACKET_FLAG_RELIABLE);</div>
<div>    if(NULL == packet){</div>
<div>        fprintf(stderr,"create packet with error\n");</div>
<div>        exit(EXIT_FAILURE);</div>
<div>    }</div>
<div>    char* d="client say";</div>
<div>    strncpy(&packet->data,d,strlen(d));</div>
<div>    ENET_peer_send(peer,1,packet);</div>
<div>    // ENET_host_broadcast(client,1,packet);</div>
<div>    // send data out</div>
<div>    ENET_host_flush(client);</div>
<div> </div>
<div>    // close connection</div>
<div>    ENET_peer_disconnect(peer,0);</div>
<div> </div>
<div>    // wait for close with success</div>
<div>    ENETEvent event;</div>
<div> </div>
<div>    while(ENET_host_service(client,&event,3000)>0){</div>
<div>        switch(event.type){</div>
<div>        case ENET_EVENT_TYPE_NONE:</div>
<div>            break;</div>
<div>        case ENET_EVENT_TYPE_RECEIVE:</div>
<div>            ENET_packet_destroy(packet);</div>
<div>            break;</div>
<div>        case ENET_EVENT_TYPE_DISCONNECT:</div>
<div>            printf("has disconnected\n");</div>
<div>            ENET_destruct();</div>
<div>            exit(EXIT_SUCCESS);</div>
<div>            break;</div>
<div>        }</div>
<div>    }</div>
<div> </div>
<div>    // force to close socket if unsuccess</div>
<div>    ENET_peer_reset(peer);</div>
<div>    printf("force disconnected\n");</div>
<div> </div>
<div>    ENET_destruct();</div>
<div>}</div>
<div>
 
 
SERVER:
</div>
<div>int start_daemon_services(ENETHost* server)</div>
<div>{</div>
<div>    ENETEvent event;</div>
<div> </div>
<div>    while(1){</div>
<div>        while(ENET_host_service(server,&event,5000)>0){</div>
<div>            switch(event.type){</div>
<div>            case ENET_EVENT_TYPE_NONE:</div>
<div> </div>
<div>                break;</div>
<div>            case ENET_EVENT_TYPE_CONNECT:</div>
<div>               printf("a new client has connected,remote host address is:  %s:%u\n",</div>
<div>                        inet_ntoa(*(struct in_addr*)&event.peer->address.host),</div>
<div>                        event.peer->address.port);</div>
<div>                event.peer->data="incoming client";</div>
<div>                break;</div>
<div>            case ENET_EVENT_TYPE_RECEIVE:</div>
<div>                printf("received package from %s\n on channel %u\tpacket size:%u\tpacket content:%s\n",</div>
<div>                       event.peer->data,</div>
<div>                       event.peer->connectID,</div>
<div>                       event.packet->dataLength,</div>
<div>                       event.packet->data);</div>
<div>                //do with package</div>
<div> </div>
<div>                //destroty it</div>
<div>                ENET_packet_destroy(event.packet);</div>
<div>                break;</div>
<div>            case ENET_EVENT_TYPE_DISCONNECT:</div>
<div>                break;</div>
<div>            default:</div>
<div>                break;</div>
<div>            }</div>
<div>        }</div>
<div>    }</div>
<div>    //reset all peers connected to server</div>
<div>    ENET_host_destroy(server);</div>
<div>}</div>
<div>

PARTNERS