Hi....I have this UDP Socket program where i need to type the string "My name is John" in client and server should return that "your ID is 1234". I am trying to run the codes but everytime it is returning the same line instead of the answer.
Here is my sample code :
#include "unp.h"
#include “string.h”
void
dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen)
{
int n;
socklen_t len;
struct args args;
struct result result;
for ( ; ; ) {
len = clilen;
n = Recvfrom(sockfd, &args, sizeof(args), 0, pcliaddr, &len);
char * s1 = “My name is John”;
char * s2 = “My name is Mary”;
if (strcmp(args.arg1, s1) == 0)
result.arg2[] = “Hi John, your ID is 1234”;
if (strcmp(args.arg1, s2) == 0)
result.arg2[] = “Hi Mary, you are not registered”;
Yah....I ran with the original code..and it works just fine...But I want to do this modification and want to print out the result...but don't know where is wrong...
I've had another look at this, and looked at the definition of struct args. The only one I can find is:
1 2 3 4
struct args {
long arg1;
long arg2;
};
If that's the one you're using, your code shouldn't even compile. The bottom line is, if we can see the all the code, it's impossible to work out what's gone wrong.