Message-ID: <3A6A6E2B.7000204@operamail.com> From: Sahab Yazdani Organization: PheonixSoft Interactive User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001204 X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: libsocket over the net... References: <3A69FEFF DOT 7020104 AT operamail DOT com> <3A6A28C3 DOT 502361A2 AT phekda DOT freeserve DOT co DOT uk> Content-Type: multipart/mixed; boundary="------------020309040203060107010000" Lines: 473 Date: Sun, 21 Jan 2001 00:05:47 -0500 NNTP-Posting-Host: 149.99.15.165 X-Complaints-To: abuse AT sprint DOT ca X-Trace: newscontent-01.sprint.ca 980053803 149.99.15.165 (Sun, 21 Jan 2001 00:10:03 EST) NNTP-Posting-Date: Sun, 21 Jan 2001 00:10:03 EST To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. --------------020309040203060107010000 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Richard Dawe wrote: [snipped my own comments] > > How are they garbled? Are the data in the wrong order? Do you get any of > the sent data when you do recv()? ok, i've been messing around with it a bit and have made a great deal of headway... i have gotten it to transmit a "MassacreHeader" structure over the network everytime perfectly. The problem now comes when I try to transmit the other two structure types: "MassacreChatPacket" and "MassacreBriefingRoomPacket". It doesn't seem to be getting any of the right data.. for instance when run the application, the proper numbers should be: mBRP.type = 0; mBRP.player = 2; mBRP.name = [A VALID ENGLSH NAME]; except we are getting... mBRP.type = 10; mBRP.player = 252; mBRP.name = "ERROR"; I believe that this is because the packets are not getting there completely, and that my method just trucates it and then the error checking routines convert the data into error values (which is only the *name* field, the type and player field are garbled by the routines). as a side note, when I print out the error using either lsck_perror or perror, i get this message "RETRIEVE1: Resource temporarily not available (EAGAIN)" over and over again with a stray "RETREIVE2: " " " " popping in there sometimes (only when data is being sent over the network). > > [snip] > I have some comments below: > > You don't need to use a nul character to terminate a string in "". > "MASS.NET" is a nul-terminated string. 'MASS.NET' is not nul-terminated > (notice the single quotes). you learn something new everyday, thanks! > > [snip] > >> if ( send( sock, (void *) &header, sizeof( MassacreHeader ), 0 )!=sizeof( MassacreHeader ) ) > > > I recommend that you always store the send() return code. It makes > debugging and recovery from error easier. E.g.: > > ... > ret = send(...); > if (ret < 0) > perror("uh-oh"); > ... thank you, i have changed it... but obviously it doesn't make a difference for the current problem. > > [snip] > as the code has changed a bit since the last time, i have again included the souce code for the packet transmitting routines again. thank you for any help you may provide. -- *********************************************************** * Sahab Yazdani * "Wizard's Third Rule: Passion rules * * Thornhill S.S * Reason." - Kolo's Journal * *********************************************************** * http://pheonixsoft.virtualave.net/ * *********************************************************** --------------020309040203060107010000 Content-Type: text/plain; name="packet.cc" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="packet.cc" // Tank Massacre V2.1 // Module: Network Code Helper (Packet Sender/Receiver) // By: Sahab Yazdani #include #include #include #include #include "packet.h" //#define DEBUG MassacreHeader CreateHeader( unsigned char packetType, unsigned char multiples ) { MassacreHeader retType; strcpy(retType.header, "MASS" ); retType.packetType = packetType; retType.multiples = multiples; return retType; } MassacreBriefingRoomPacket CreateBriefingRoomPacket( char update, unsigned char player, unsigned char type, char name[] ) { MassacreBriefingRoomPacket retType; retType.update = update; retType.player = player; retType.type = type; strcpy( retType.name, name ); return retType; } MassacreChatPacket CreateChatPacket( char message[] ) { MassacreChatPacket retType; strcpy( retType.message, message ); return retType; } bool SendHeader( int sock, unsigned char packetType, unsigned char multiples = 1 ) { MassacreHeader header; ssize_t ret; strcpy( header.header, "MASS" ); header.packetType = packetType; header.multiples = multiples; ret = send( sock, (void *) &header, sizeof( MassacreHeader ), 0 ); if ( ret!=sizeof( MassacreHeader ) ) return false; else return true; } MassacreHeader ReceiveHeader( int sock ) { unsigned char *tempBuffer = new unsigned char[sizeof( MassacreHeader )]; MassacreHeader header; int len=0, len1=0, smH; bool err=false; smH = sizeof( MassacreHeader ); memset( (void *) tempBuffer, 0, smH ); len = recv( sock, ( void *) tempBuffer, smH, 0 ); if ( len == 0 ) err = true; else { // printf( "len: %i\n", len ); if ( len == -1 ) { if ( errno!=EAGAIN ) { perror( "RETRIEVE1" ); err=true; } } else { while ( len < smH ) { len1 = recv( sock, ( void * ) &tempBuffer[len], smH - len, 0 ); if ( len1 == -1 ) { if ( errno!=EAGAIN ) { perror( "RETRIEVE2" ); err=true; } break; } len += len1; } } } if (!err) { memcpy( (void *) &header, (void *) tempBuffer, smH ); if ( strstr( header.header, "MASS" )==NULL ) header.packetType = PACKETSTYLE_ERROR; } else { header.packetType=PACKETSTYLE_ERROR; header.multiples = errno; } delete tempBuffer; return header; } int BroadcastHeader( int socks[], int sockets, int retSocket, MassacreHeader mH ) { int sC; int retVal=0; for ( sC=0;sC