简体   繁体   English

无法连接到本地网络中的服务器

[英]cant connect to server in local network

I have 2 Computers.我有2台电脑。 My Server is running on the Debian one while my Client is running on the Windows PC.我的服务器在 Debian 上运行,而我的客户端在 Windows PC 上运行。 The IP of my Server is 192.168.2.113, the one of my Client is 192.168.2.122.我的服务器的 IP 是 192.168.2.113,我的客户端是 192.168.2.122。

When I telnet 127.0.0.1 or 192.168.2.113 on the Server Machine there is no problem.当我在服务器机器上 telnet 127.0.0.1 或 192.168.2.113 时没有问题。 The Problem is that I cant connect to the Server from my Client.问题是我无法从客户端连接到服务器。

I opened the port 50002 via iptables with the comment:我通过 iptables 打开了端口 50002,并带有以下注释:

sudo iptables -A INPUT -p tcp --dport 50002 --jump ACCEPT

The main.cpp of my Server:我的服务器的 main.cpp:

#include<stdio.h>
#include<string.h>  //strlen
#include<sys/socket.h>
#include<arpa/inet.h>   //inet_addr
#include<unistd.h>  //write

int main(int argc , char *argv[])
{
int socket_desc , client_sock , c , read_size;
struct sockaddr_in server , client;
char client_message[2000];

//Create socket
socket_desc = socket(AF_INET , SOCK_STREAM , 0);
if (socket_desc == -1)
{
    printf("Could not create socket");
}
puts("Socket created");

//Prepare the sockaddr_in structure
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons( 50002 );

//Bind
if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
{
    //print the error message
    perror("bind failed. Error");
    return 1;
}
puts("bind done");

//Listen
listen(socket_desc , 3);

//Accept and incoming connection
puts("Waiting for incoming connections...");
c = sizeof(struct sockaddr_in);

//accept connection from an incoming client
client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c);
if (client_sock < 0)
{
    perror("accept failed");
    return 1;
}
puts("Connection accepted");

//Receive a message from client
while( (read_size = recv(client_sock , client_message , 2000 , 0)) > 0 )
{
    //Send the message back to client
    write(client_sock , client_message , strlen(client_message));
}

if(read_size == 0)
{
    puts("Client disconnected");
    fflush(stdout);
}
else if(read_size == -1)
{
    perror("recv failed");
}

return 0;
}

Something strange i noticed is that I can connect to www.google.com in firefox but not in telnet (on my client pc):我注意到的一些奇怪的事情是,我可以在 firefox 中连接到 www.google.com 但不能在 telnet 中(在我的客户端 pc 上):

telnet>o www.google.com 80远程登录>o www.google.com 80

I only get 400-badrequest error我只收到 400-badrequest 错误

help is very appriciated.帮助是非常appriciated。

Suggestions:建议:

Step 1) establish that you can ping your server from windows.步骤 1) 确定您可以从 windows ping 您的服务器。 This way we eliminate potential network configuration issues.通过这种方式,我们消除了潜在的网络配置问题。 Make changes to your firewall if needed.如果需要,对防火墙进行更改。

ping 192.168.2.113平 192.168.2.113

Step 2) Ping from server to access windows.步骤 2) 从服务器 ping 以访问 windows。 Windows firewall can prevent communication as well. Windows 防火墙也可以阻止通信。

ping 192.168.2.112平 192.168.2.112

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 提升asio服务器客户端。 在局域网中的两台计算机之间连接 - boost asio server-client. Connect between two computers in local area network 用于本地网络运行的客户端服务器体系结构 - Client server architecture for local an network run 无法连接到Windows上的本地服务器 - Can't connect to local server on Windows 尝试将iPod touch连接到我的服务器时网络超时 - Network time out when trying to connect ipod touch to my server 无法在C ++中将数据从服务器发送到本地网络上的客户端 - Unable to Send data from Server to client on local network in C++ 如何通过本地网络将PvD(Physx Visual Debugger)连接到另一台PC - How to Connect PvD(Physx Visual Debugger) to another PC over a local network QObject :: connect无法将信号连接到* this *对象的插槽 - QObject::connect cant connect signal to a slot of *this* object 如何通过本地LAN使用网络别名自动访问嵌入式设备的Web服务器? - How can automatically access an embedded device's web server using a network alias over a local LAN? ASIO客户端服务器在同一台PC上连接正常,但在本地网络上失败 - ASIO Client Server Connects Fine on the same PC, but Fails across a Local Network 获取文件的位置:网络还是本地 - Getting location of a file: network or local
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM