UltraDog
asked on
Protecting my TCP or UDP conenction.
Hi!
I have a client and a server which communicate through TCP and UDP.
I'd like to prevent receiving messages from other processes that may try to connect to my ports.
I take the stream of bytes and make an object out of it, but if this is just a random stream - the program will crash.
How can I do it?
thanks :)
I have a client and a server which communicate through TCP and UDP.
I'd like to prevent receiving messages from other processes that may try to connect to my ports.
I take the stream of bytes and make an object out of it, but if this is just a random stream - the program will crash.
How can I do it?
thanks :)
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Just make your header longer, e.g. as in the example above. It would be *very* coincidential that four bytes match by chance.
In any case, you need to make your protocol implementation robust enough to handle bad packets.
At minimum use a giant try/catch block to discard message and close the connection. It shouldnt be possible to crash your app with a bad packet.
At minimum use a giant try/catch block to discard message and close the connection. It shouldnt be possible to crash your app with a bad packet.
Are you trying to protect against malice, or against an accident ?
ASKER
against accidents :)
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I'd rather combine the two ideas - that is, if the header does not match, you can skip calculating a checksum, but if it does, a matching checksum will make absolutely sure that the packet originated from a trustworthy source.
ASKER
suppose I put in my header the letter 'A' and the length of the message and so does the other process?