Jump to content

View more

Image of the Day

Project built to test Unity's networking
#gamedev #indiedev #screenshotsaturday #indiedevhour #madewithunity https://t.co/vcsky4QFKr
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

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

2: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 hsine   Members   

112
Like
0Likes
Like

Posted 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>

Edited by rip-off, 09 January 2013 - 08:33 AM.


#2 rip-off   Moderators   

10809
Like
0Likes
Like

Posted 09 January 2013 - 08:32 AM

Can you post any error message(s) or describe the expected and erroneous behaviour that you are observing?

 

Please use [ code ] tags (without spaces) around your source code, it will render it in a nice, syntax highlighted box for ease of viewing.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.