[ENet-discuss] Stops sending after 4096bytes

Brian bdm4980 at gmail.com
Tue Dec 28 11:08:33 PST 2004


Right now the server just keeps calling serverLoop() in an infinite
while(true) loop.  Client code is pretty small right now as well.
Didn't include all the server/client setup to reduce the size of the
code copied in here, but they both get setup and connect to each
other.  Server receives the 4096 bytes of messages from client then
stops receiving...

//server code
void serverLoop()
{
    
    /* Wait up to 1000 milliseconds for an event. */
	while (enet_host_service (host, & event, 20) > 0)
    {
		printf("Starting Polling...\n");

        switch (event.type)
        {
        case ENET_EVENT_TYPE_CONNECT:
			
            printf("A new client connected from %d:%d\n", event.peer
-> address.host,event.peer -> address.port);

		    /* Store any relevant client information here. */
            event.peer -> data = "Client information";

            break;

        case ENET_EVENT_TYPE_RECEIVE:
			count++;
			printf ("A packet of length %u containing %s was received from %s
on channel %u.\n",
                    event.packet -> dataLength,
                    event.packet -> data,
                    event.peer -> data,
                    event.channelID);

            /* Clean up the packet now that we're done using it. */
            enet_packet_destroy (event.packet);
            
            break;
           
        case ENET_EVENT_TYPE_DISCONNECT:
            printf( "%s disconected %d\n", event.peer->data, count);

            /* Reset the peer's client information. */

            event.peer -> data = NULL;
        }
    }
}


/*************************************************************************************************/
//client code                                                         
                                              /
/************************************************************************************************/

char szT[7];		//temp string to hold input txt
		int counttemp=0;
		while(true)
		{
			_snprintf( szT, sizeof( szT ) - 1, "%d", counttemp++ );
			Sleep(5);
			sock->sendData(szT);
		}


void Socket::sendData(char *data)
{
	/* Create a reliable packet of size 7 containing "packet\0" */
    ENetPacket * packet = enet_packet_create (data, strlen(data) +
1,ENET_PACKET_FLAG_RELIABLE);

    /* Extend the packet so and append the string "foo", so it now */
    /* contains "packetfoo\0"                                      */
    //enet_packet_resize (packet, strlen ("packetfoo") + 1);
    //strcpy (& packet -> data [strlen ("packet")], "foo");
    
    /* Send the packet to the peer over channel id 3. */
    /* One could also broadcast the packet by         */
    /* enet_host_broadcast (host, 3, packet);         */
    enet_peer_send (peer, 0, packet);
	enet_host_flush (host);

}

I tried throwing in random flush statements in all the loops with no success.

Thanks again,
Brian

On Tue, 28 Dec 2004 17:45:26 -0800, Lee Salzman <lsalzman1 at cox.net> wrote:
> Sounds like you're just not flushing something somewhere. I couldn't
> tell you more without seeing how you're using ENet.
> 
> Lee
> 
> On Tue, Dec 28, 2004 at 11:15:39AM -0600, Brian wrote:
> > Hi,
> >
> > I'm trying to implement enet in an application, but I can only send
> > 4096 bytes of data (4096 empty packets, 64 x 64 byte packets etc) and
> > then the server will eventually say the client disconnected (I assume
> > timed out). I have been through the tutorial on the cubik site a dozen
> > times and I can't find anything I'm missing. Because of the constant
> > size, I'm sure its a buffer issue, but I just can't figure out where
> > exactly the issue is.
> >
> > Stepping through the client in the debugger,  the enet_host_flush
> > function calls enet_protocol_send_outgoing_commands where host ->
> > commandCount is set to 0 and never assigned another value so it hits
> > the continue statement after checking if if (host -> commandCount ==
> > 0).
> >
> > Anyone know what could be the cause or speculate on things I might try
> > to solve the problem?
> >
> > Thanks in advance!
> > Brian
> 
> 
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
> 
> 
>


More information about the ENet-discuss mailing list