<div dir="ltr">hi£¬sorry to reply such late!<div style>I put send and receive in two different threads</div><div style>here is the part of sending:</div><div style><div><b><font color="#ff0000"><span class="" style="white-space:pre">   </span>while (!mSendBuffer.isEmpty() && mConnect)</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">     </span>{</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">            </span>if(safety)</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">                   </span>GlobalThreadLock.Lock();</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>PacketBuffer* pack = mSendBuffer.getFront();</font></b></div><div><b><font color="#ff0000"><br></font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">          </span>const char* pszText = (const char*)pack->buf.base();</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>//ELOG("buf :%s",pszText);</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">         </span>if(NULL == pszText)</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>{</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">                    </span>ELOG("send buf is null");</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">                     </span>continue;</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">            </span>}</font></b></div><div><span class="" style="white-space:pre"><b><font color="#ff0000">                    </font></b></span></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>ENetPacket *packet=enet_packet_create(pszText,strlen(pszText)+1,ENET_PACKET_FLAG_RELIABLE); </font></b></div><div><b><font color="#ff0000"><br>
</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">          </span>if (NULL == mPeer)</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">           </span>{</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">                     </span>ELOG("mPeer is NULL");</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">                     </span>return;</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>}</font></b></div><div><span class="" style="white-space:pre"><b><font color="#ff0000">            </font></b></span></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>int channle = rand()%mChannelLimit;</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>if(pack->flags)</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">                   </span>enet_host_broadcast(mHost ,channle ,packet);</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>else</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">         </span>{</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">                    </span>int reval = enet_peer_send(mPeer,channle,packet);</font></b></div>
<div><b><font color="#ff0000"><br></font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">                      </span>if (reval != 0)</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">                      </span>{</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">                             </span>ELOG("send msg failed");</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">                           </span>return;</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">                     </span>}</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">            </span>}</font></b></div><div><span class="" style="white-space:pre"><b><font color="#ff0000">            </font></b></span></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>pack->buf.clear();</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">                </span>delete pack;</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">             </span>mSendBuffer.dequeue();</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">               </span>if(safety)</font></b></div>
<div><b><font color="#ff0000"><span class="" style="white-space:pre">                     </span>GlobalThreadLock.Unlock();</font></b></div><div><b><font color="#ff0000"><span class="" style="white-space:pre">   </span>}</font></b></div><div>
<b><font color="#ff0000"><br></font></b></div><div style><font color="#000000"><b>and here is the part of receiving:</b></font></div><div style><font color="#000000"><b><br></b></font></div><div style><b><font color="#ff0000"><div>
while(enet_host_service(mHost,&mEvent,mRecvDelay)>=0)</div><div><span class="" style="white-space:pre">    </span>{</div><div><span class="" style="white-space:pre">          </span>if(Thread_Pause)</div><div><span class="" style="white-space:pre">           </span>{</div>
<div><span class="" style="white-space:pre">                    </span>ELOG("Thread wait");</div><div><span class="" style="white-space:pre">                     </span>GlobalThreadLock.wait();</div><div><span class="" style="white-space:pre">           </span>}</div>
<div><span class="" style="white-space:pre">            </span>if(mEvent.type==ENET_EVENT_TYPE_CONNECT) </div><div><span class="" style="white-space:pre">             </span>{</div><div><span class="" style="white-space:pre">                  </span>if(mType == SERVER)</div>
<div><span class="" style="white-space:pre">                    </span>{</div><div><span class="" style="white-space:pre">                          </span>if(safety)</div><div><span class="" style="white-space:pre">                                 </span>GlobalThreadLock.Lock();</div><div>
<span class="" style="white-space:pre">                               </span>static unsigned int num=0;</div><div><span class="" style="white-space:pre">                         </span>ENetAddress remote=mEvent.peer->address; </div><div><span class="" style="white-space:pre">                          </span>char ip[256];</div>
<div><span class="" style="white-space:pre">                            </span>enet_address_get_host_ip(&remote,ip,256);</div><div><span class="" style="white-space:pre">                              </span>ELOG("ip: %s has been connected, NO.: %d  ,port:  %d",ip,num,remote.port);</div>
<div><span class="" style="white-space:pre">                            </span>mEvent.peer->data=(void*)num++;</div><div><span class="" style="white-space:pre">                         </span>ELOG("user data: %d",mEvent.data);</div><div><span class="" style="white-space:pre">                               </span>if(NULL == mPeer)</div>
<div><span class="" style="white-space:pre">                                    </span>mPeer = mEvent.peer;</div><div><span class="" style="white-space:pre">                               </span>mConnect = true;</div><div><span class="" style="white-space:pre">                           </span>if(safety)</div>
<div><span class="" style="white-space:pre">                                    </span>GlobalThreadLock.Unlock();</div><div><span class="" style="white-space:pre">                 </span>}</div><div><span class="" style="white-space:pre">          </span>}</div><div><span class="" style="white-space:pre">          </span>else if(mEvent.type==ENET_EVENT_TYPE_RECEIVE) </div>
<div><span class="" style="white-space:pre">            </span>{</div><div><span class="" style="white-space:pre">                  </span>if(safety)</div><div><span class="" style="white-space:pre">                         </span>GlobalThreadLock.Lock();</div><div><br>
</div><div><span class="" style="white-space:pre">                        </span>if (mRecvBuffer.isFull())</div><div><span class="" style="white-space:pre">                  </span>{</div><div><span class="" style="white-space:pre">                          </span>DequeueRecvBuf();</div>
<div><span class="" style="white-space:pre">                    </span>}</div><div><br></div><div><span class="" style="white-space:pre">                 </span>PacketBuffer* packet = new PacketBuffer;</div><div><span class="" style="white-space:pre">                   </span>packet->flags = 0;</div>
<div><span class="" style="white-space:pre">                    </span>packet->buf.push((const char*)mEvent.packet->data ,mEvent.packet->dataLength);</div><div><span class="" style="white-space:pre">                    </span>mRecvBuffer.enqueue(packet);</div>
<div><br></div><div><span class="" style="white-space:pre">                   </span>enet_packet_destroy(mEvent.packet); </div><div><br></div><div><span class="" style="white-space:pre">                 </span>if(safety)</div><div><span class="" style="white-space:pre">                         </span>GlobalThreadLock.Unlock();</div>
<div><span class="" style="white-space:pre">            </span>}</div><div><span class="" style="white-space:pre">          </span>else if(mEvent.type==ENET_EVENT_TYPE_DISCONNECT) </div><div><span class="" style="white-space:pre">             </span>{</div>
<div><span class="" style="white-space:pre">                    </span>ENetAddress remote=mEvent.peer->address; </div><div><span class="" style="white-space:pre">                  </span>char ip[256];</div><div><span class="" style="white-space:pre">                      </span>enet_address_get_host_ip(&remote,ip,256);</div>
<div><span class="" style="white-space:pre">                    </span>if(mType == CLIENT)</div><div><span class="" style="white-space:pre">                        </span>{</div><div><span class="" style="white-space:pre">                          </span>ELOG("NO. %d remote has closed connection",mEvent.peer->data);</div>
<div><span class="" style="white-space:pre">                            </span>if (!mInitiative)</div><div><span class="" style="white-space:pre">                          </span>{</div><div><span class="" style="white-space:pre">                                  </span>mConnect = false;</div><div>
<span class="" style="white-space:pre">                                       </span>CallBack(NET_DisConnectWithServer,ip);</div><div><span class="" style="white-space:pre">                             </span>}</div><div><span class="" style="white-space:pre">                  </span>}</div><div>
<span class="" style="white-space:pre">                       </span>else if(mType == SERVER)</div><div><span class="" style="white-space:pre">                   </span>{</div><div><span class="" style="white-space:pre">                          </span>CallBack(NET_ClientDisConnect,ip);</div>
<div><span class="" style="white-space:pre">                            </span>ELOG("NO. %d remote has closed connection",mEvent.peer->data);</div><div><span class="" style="white-space:pre">                        </span>}</div><div><span class="" style="white-space:pre">          </span>}</div>
<div><span class="" style="white-space:pre">    </span>}</div></font></b></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/5/25 Payton Turnage <span dir="ltr"><<a href="mailto:paytonturnage@gmail.com" target="_blank">paytonturnage@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Can you post a block of relevant code or link to a gist? Also, note that enet_peer_send does not actually send anything, but just queues it. If it returns 0 it means the packet was successfully queued, and enet_host_service will send it on the next opportunity.</div>

<div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Thu, May 23, 2013 at 11:22 PM, <a href="mailto:zxz3121@gmail.com" target="_blank">zxz3121@gmail.com</a> <span dir="ltr"><<a href="mailto:zxz3121@gmail.com" target="_blank">zxz3121@gmail.com</a>></span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><u></u>





<div style="MARGIN:10px">
<div>I got a issue recently £¬it happened randomly£¬but the probability is very 
small¡£</div>
<div>when I created a client and connect to server success£¬send and receive is 
all normal,but the client suddenly can`t send the buffer at a moment and still 
can receive buf£¬I check the enet_peer_send function it return 0 £¬it`s means 
sending normal.£¬I wonder if the issue is caused by server</div>
<div> </div>
<hr style="WIDTH:210px;min-height:1px" align="left" color="#b5c4df" size="1"><span><font color="#888888">

<div><span><a href="mailto:zxz3121@gmail.com" target="_blank">zxz3121@gmail.com</a></span></div></font></span></div>
<br></div></div>_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>