UDP C Server not receiving packets?

Here are a few minor points: In your server, set size_client = sizeof(struct_client) before every call to recvfrom. It is both an input and output parameter, so you want to make sure the output from one call does not interfere with the input to the next. Make sure to set the last byte of buf to '\0' to prevent your printf from reading memory beyond the boundary.

What is cod? Where did it come from? I think you meant to test numbytes.

Setting bufstrlen(buf) - 1 = '\0' chops off the last character of the buffer; is that what you were trying to do? And the major reason it doesn't work: You never initialized nr, so there is no telling what sendto is sending. It certainly isn't sending buf, which I think was what you wanted... You probably want this: sendto(s, buf, sizeof(buf), ...).

I modified my code with your suggestions, but still the same. All these are things I look after (like the '\0'), but now it's just annoying as I can't figure out the problem and I posted the code after some hasty changes. – joanna Mar 18 at 14:35.

Unless I'm missing something drastic, you're just sending garbage here. Nr is never initialized on the sender, except in a comment. Buf is being initialized, but not used anywhere.

Can you try changing the sendto part to something like: result = sendto(s, buf, strlen(buf)+1, 0, (struct sockaddr*) &struct_client, size_client).

In your client code, the nr variable that is sent over the net is not initialized and can point to whatever it wants. You probably want to send your buf array instead.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions