Skip to content

Commit 9a24d35

Browse files
authored
Merge pull request #174 from RonEld/seperate_server_name
Separate server name
2 parents eb73230 + 5cc8614 commit 9a24d35

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

tls-client/HelloHttpsClient.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ const char *HelloHttpsClient::HTTP_HELLO_STR = "Hello world!";
7070
const char *HelloHttpsClient::HTTP_OK_STR = "200 OK";
7171

7272
HelloHttpsClient::HelloHttpsClient(const char *in_server_name,
73+
const char *in_server_addr,
7374
const uint16_t in_server_port,
7475
mbedtls_platform_context* in_platform_ctx) :
7576
socket(),
7677
server_name(in_server_name),
78+
server_addr(in_server_addr),
7779
server_port(in_server_port),
7880
/* The platform context is passed just in case any crypto calls need it.
7981
* Please refer to https://github.com/ARMmbed/mbedtls/issues/1200 for more
@@ -114,12 +116,12 @@ int HelloHttpsClient::run()
114116
return ret;
115117

116118
/* Start a connection to the server */
117-
if ((ret = socket.connect(server_name, server_port)) != NSAPI_ERROR_OK) {
119+
if ((ret = socket.connect(server_addr, server_port)) != NSAPI_ERROR_OK) {
118120
mbedtls_printf("socket.connect() returned %d\n", ret);
119121
return ret;
120122
}
121123
mbedtls_printf("Successfully connected to %s at port %u\n",
122-
server_name, server_port);
124+
server_addr, server_port);
123125

124126
/* Start the TLS handshake */
125127
mbedtls_printf("Starting the TLS handshake...\n");

tls-client/HelloHttpsClient.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ class HelloHttpsClient
5656
* Construct an HelloHttpsClient instance
5757
*
5858
* \param[in] in_server_name
59+
* The server host name
60+
* \param[in] in_server_addr
5961
* The server domain/IP address
6062
* \param[in] in_server_port
6163
* The server port
6264
*/
6365
HelloHttpsClient(const char *in_server_name,
66+
const char *in_server_addr,
6467
const uint16_t in_server_port,
6568
mbedtls_platform_context* in_platform_ctx);
6669

@@ -192,9 +195,14 @@ class HelloHttpsClient
192195
TCPSocket socket;
193196

194197
/**
195-
* The domain/IP address of the server to contact
198+
* The server host name to contact
196199
*/
197200
const char *server_name;
201+
202+
/**
203+
* The domain/IP address of the server to contact
204+
*/
205+
const char *server_addr;
198206
/**
199207
* The port number to use in the connection
200208
*/

tls-client/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
/* Domain/IP address of the server to contact */
4242
const char SERVER_NAME[] = "os.mbed.com";
43+
const char SERVER_ADDR[] = "os.mbed.com";
4344

4445
/* Port used to connect to the server */
4546
const int SERVER_PORT = 443;
@@ -73,8 +74,9 @@ int main()
7374
#endif /* MBEDTLS_MAJOR_VERSION */
7475

7576
/* Allocate a HTTPS client */
76-
client = new (std::nothrow) HelloHttpsClient(SERVER_NAME, SERVER_PORT,
77+
client = new (std::nothrow) HelloHttpsClient(SERVER_NAME, SERVER_ADDR, SERVER_PORT,
7778
&platform_ctx);
79+
7880
if (client == NULL) {
7981
mbedtls_printf("Failed to allocate HelloHttpsClient object\n"
8082
"\nFAIL\n");

0 commit comments

Comments
 (0)