如何更改地址?
我在将输入数据发送到本地服务器的代码中添加了一个简单的代码。 现在我不知道如何将地址更改为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函数将输入数据发送到127.0.0.1:8080 但不知道怎么改ip。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Ngrok 在您的电脑上本地运行,因此他在 127.0.0.1 上运行,Ngrok 在您的电脑上不是 root,因此当您不是 root 时,他必须使用默认的 http 端口 8080。
我邀请您查看 ngrok 文档:
https://ngrok.com/docs
本教程:
https://ngrok.com/docs/guides/ how-to-set-up-a-custom-domain
那么你必须改变
到
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
to