mirror of https://github.com/dirtbags/moth.git
Making client do some snazzy stuff like sendto(). ~Cherish
This commit is contained in:
parent
da4e850386
commit
5cffbd9632
|
@ -94,10 +94,22 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
char recvString[500]; /* Buffer for received string */
|
char recvString[500]; /* Buffer for received string */
|
||||||
int recvStringLen; /* Length of received string */
|
int recvStringLen; /* Length of received string */
|
||||||
|
struct sockaddr_in6 from;
|
||||||
|
socklen_t fromlen = sizeof(from);
|
||||||
|
char sendString[] = "Token: banana\n";
|
||||||
|
char errorString[] = "That is not correct! Try again!\n";
|
||||||
|
|
||||||
/* Receive a single datagram from the server */
|
/* Receive a single datagram from the server */
|
||||||
if ((recvStringLen = recvfrom(sock, recvString, sizeof(recvString) - 1, 0, NULL, 0)) < 0) DieWithError("recvfrom() failed");
|
if ((recvStringLen = recvfrom(sock, recvString, sizeof(recvString) - 1, 0, (struct sockaddr *)&from, &fromlen)) < 0) DieWithError("recvfrom() failed");
|
||||||
recvString[recvStringLen] = '\0';
|
recvString[recvStringLen] = '\0';
|
||||||
|
if(strcmp(recvString, "hello")==0) {
|
||||||
|
printf("Correct!!\n");
|
||||||
|
// printf("Token: banana\n");
|
||||||
|
sendto(sock, sendString, sizeof(sendString) - 1, 0, (struct sockaddr *)&from, fromlen);
|
||||||
|
} else {
|
||||||
|
// printf("That isn't correct! Try again!\n");
|
||||||
|
sendto(sock, errorString, sizeof(errorString) - 1, 0, (struct sockaddr *)&from, fromlen);
|
||||||
|
}
|
||||||
|
|
||||||
/* Print the received string */
|
/* Print the received string */
|
||||||
printf("Received string [%s]\n", recvString);
|
printf("Received string [%s]\n", recvString);
|
||||||
|
|
Loading…
Reference in New Issue