2个回答
展开全部
/*server.c*/
#include <string.h>
#include <stdio.h>
#include <netinet/in.h>
#include <stdlib.h>
#define SERV_PORT 8000
int main()
{
int sockfd,n,servaddr_len,client_len,connfd;
char * server_ip = "127.0.0.1";
char buf[80];
struct sockaddr_in server,client;
sockfd = socket (AF_INET,SOCK_STREAM,0);
bzero(&server,sizeof(server));
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(server_ip);
server.sin_port = htons(SERV_PORT);
servaddr_len = sizeof(server);
client_len=sizeof(client);
bind(sockfd,(struct sockaddr *) &server,servaddr_len);
listen(sockfd,6);
while(1)
{
bzero(buf,sizeof(buf));
printf("等待读取数据.......\n");
connfd=accept(sockfd,(struct sockaddr *)&client,&client_len);
n = read(connfd,buf,sizeof(buf));
write(connfd,buf,n);
printf("读取的数据为:%s\n",buf);
}
close(sockfd);
return 0;
}
<?php
$server_ip="127.0.0.1";
$port = 8000;
if($_POST['submit'])
{
$buf=trim($_POST['buf']);
$sockfd=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)or die("创建失败");
socket_connect($sockfd,$server_ip,$port)or die("连接错误");
socket_write($sockfd,$buf,strlen($buf))or die("写入错误");
$a=socket_read($sockfd,80);
echo $a;
$buf="";
socket_close($sockfd);
}
?>
<form action="tcpclient.php" method="post">
请选则发送方式:<br><input type=text name="buf">
<input type=submit name="submit" value="发送">
</form>
tcp方式不能通信解决方法
执行:getsebool -a |grep http
查看httpd_can_network_connect --> off 是否为打开状态
执行:setsebool httpd_can_network_connect on 把httpd_can_network_connect设置为打开状态
tcp方式不能通信解决方法
执行:getsebool -a |grep http
查看httpd_can_network_connect --> off 是否为打开状态
执行:setsebool httpd_can_network_connect on 把httpd_can_network_connect设置为打开状态
#include <string.h>
#include <stdio.h>
#include <netinet/in.h>
#include <stdlib.h>
#define SERV_PORT 8000
int main()
{
int sockfd,n,servaddr_len,client_len,connfd;
char * server_ip = "127.0.0.1";
char buf[80];
struct sockaddr_in server,client;
sockfd = socket (AF_INET,SOCK_STREAM,0);
bzero(&server,sizeof(server));
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(server_ip);
server.sin_port = htons(SERV_PORT);
servaddr_len = sizeof(server);
client_len=sizeof(client);
bind(sockfd,(struct sockaddr *) &server,servaddr_len);
listen(sockfd,6);
while(1)
{
bzero(buf,sizeof(buf));
printf("等待读取数据.......\n");
connfd=accept(sockfd,(struct sockaddr *)&client,&client_len);
n = read(connfd,buf,sizeof(buf));
write(connfd,buf,n);
printf("读取的数据为:%s\n",buf);
}
close(sockfd);
return 0;
}
<?php
$server_ip="127.0.0.1";
$port = 8000;
if($_POST['submit'])
{
$buf=trim($_POST['buf']);
$sockfd=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)or die("创建失败");
socket_connect($sockfd,$server_ip,$port)or die("连接错误");
socket_write($sockfd,$buf,strlen($buf))or die("写入错误");
$a=socket_read($sockfd,80);
echo $a;
$buf="";
socket_close($sockfd);
}
?>
<form action="tcpclient.php" method="post">
请选则发送方式:<br><input type=text name="buf">
<input type=submit name="submit" value="发送">
</form>
tcp方式不能通信解决方法
执行:getsebool -a |grep http
查看httpd_can_network_connect --> off 是否为打开状态
执行:setsebool httpd_can_network_connect on 把httpd_can_network_connect设置为打开状态
tcp方式不能通信解决方法
执行:getsebool -a |grep http
查看httpd_can_network_connect --> off 是否为打开状态
执行:setsebool httpd_can_network_connect on 把httpd_can_network_connect设置为打开状态
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询