'how do I change the address?
I added a simple code to the code that sends input data to the local server. Now I do not know how to change the address to ngrok.
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#define PORT 8080
int n,t;
char hello[10];
int main(int argc, char const *argv[]){
int sock = 0, valread;
struct sockaddr_in serv_addr;
char buffer[1024] = {0};
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
printf("\n Socket creation error \n");
return -1;
}
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
// Convert IPv4 and IPv6 addresses from text to binary form
if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
{
printf("\nInvalid address/ Address not supported \n");
return -1;
}
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
printf("\nConnection Failed \n");
return -1;
}
send(sock , hello , strlen(hello) , 0 );
return 0;
}
send function send input data to 127.0.0.1:8080 But I don't know how to change ip.
Solution 1:[1]
Ngrok is running in local on your pc so his running on 127.0.0.1, Ngrok is not root on your pc so he has to use the port 8080 default for http when your not root.
I invite you to check the ngrok documentation: https://ngrok.com/docs
And this tutorial: https://ngrok.com/docs/guides/how-to-set-up-a-custom-domain
Then you have to change
// Convert IPv4 and IPv6 addresses from text to binary form if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
to
// Convert IPv4 and IPv6 addresses from text to binary form if(inet_pton(AF_INET, "new_Ngrok_IP_adresse", &serv_addr.sin_addr)<=0)"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Louis |
