removed additional methods so that the code reads linearly in server-psk and client-psk
parent
95461c350f
commit
6c518455dd
|
@ -58,36 +58,11 @@ static inline unsigned int My_Psk_Client_Cb(WOLFSSL* ssl, const char* hint,
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* this function will send the inputted string to the server and then
|
|
||||||
* recieve the string from the server outputing it to the termial
|
|
||||||
*/
|
|
||||||
int SendReceive(WOLFSSL* ssl)
|
|
||||||
{
|
|
||||||
char sendline[MAXLINE]="Hello Server"; /* string to send to the server */
|
|
||||||
char recvline[MAXLINE]; /* string received from the server */
|
|
||||||
|
|
||||||
/* write string to the server */
|
|
||||||
if (wolfSSL_write(ssl, sendline, MAXLINE) != sizeof(sendline)) {
|
|
||||||
printf("Write Error to Server\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* flags if the Server stopped before the client could end */
|
|
||||||
if (wolfSSL_read(ssl, recvline, MAXLINE) < 0 ) {
|
|
||||||
printf("Client: Server Terminated Prematurely!\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* show message from the server */
|
|
||||||
printf("Server Message: %s\n", recvline);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ret, sockfd;
|
int ret, sockfd;
|
||||||
|
char sendline[MAXLINE]="Hello Server"; /* string to send to the server */
|
||||||
|
char recvline[MAXLINE]; /* string received from the server */
|
||||||
WOLFSSL* ssl;
|
WOLFSSL* ssl;
|
||||||
WOLFSSL_CTX* ctx;
|
WOLFSSL_CTX* ctx;
|
||||||
struct sockaddr_in servaddr;;
|
struct sockaddr_in servaddr;;
|
||||||
|
@ -148,11 +123,20 @@ int main(int argc, char **argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* takes inputting string and outputs it to the server */
|
/* write string to the server */
|
||||||
ret = SendReceive(ssl);
|
if (wolfSSL_write(ssl, sendline, MAXLINE) != sizeof(sendline)) {
|
||||||
if (ret != 0) {
|
printf("Write Error to Server\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check if server ended before client could read a response */
|
||||||
|
if (wolfSSL_read(ssl, recvline, MAXLINE) < 0 ) {
|
||||||
|
printf("Client: Server Terminated Prematurely!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* show message from the server */
|
||||||
|
printf("Server Message: %s\n", recvline);
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
wolfSSL_free(ssl);
|
wolfSSL_free(ssl);
|
||||||
|
|
|
@ -62,10 +62,10 @@ int main()
|
||||||
int n; /* length of string read */
|
int n; /* length of string read */
|
||||||
int listenfd, connfd;
|
int listenfd, connfd;
|
||||||
int opt;
|
int opt;
|
||||||
struct sockaddr_in cliAddr, servAddr;
|
|
||||||
char buff[MAXLINE];
|
char buff[MAXLINE];
|
||||||
char buf[MAXLINE]; /* string read from client */
|
char buf[MAXLINE]; /* string read from client */
|
||||||
char response[] = "I hear ya for shizzle";
|
char response[] = "I hear ya for shizzle";
|
||||||
|
struct sockaddr_in cliAddr, servAddr;
|
||||||
socklen_t cliLen;
|
socklen_t cliLen;
|
||||||
WOLFSSL_CTX* ctx;
|
WOLFSSL_CTX* ctx;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue