Mail Archives: djgpp/2001/01/20/20:21:37
Hello.
Sahab Yazdani wrote:
> i am attempting to test my application (which uses libsocket) for over
> the net usage. It doesn't work. It accepts the connection from the
> client, but then whatever packets I send get garbled up
How are they garbled? Are the data in the wrong order? Do you get any of
the sent data when you do recv()?
> (do I have to make everything in packet structures network edian??)
Only if you want to send data between machines with different endianness,
i.e. if you want your program to be portable. If you only want to use
Intel PCs, then you don't have to worry about this.
[snip]
> I have included the source code for the actual transmission and receive
> of packets with this message in the hope that somebody on this newsgroup
> might be able to help me out...
I have some comments below:
[snip]
> strcpy(retType.header, "MASS.NET\0" );
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).
[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");
...
[snip]
> lsck_perror("ERROR");
lsck_perror() is obsolete now - libsocket comes with a modified versions
of perror() and strerror() that handle socket error codes.
I cannot see anything obviously wrong with your program. You have packed
the data structures for transmission, which is a wise idea. I realise this
post is not much help, but if you could describe how the data is garbled,
I may be able to help better.
Bye,
--
Richard Dawe <richdawe AT bigfoot DOT com> http://www.bigfoot.com/~richdawe/
"The soul is the mirror of an indestructible universe."
--- Gottfried W. Leibniz
- Raw text -