C:为什么此服务器/客户端设置只能在一台计算机上运行? [英] C: Why does this server / client setup only work inside one computer?

查看:41
本文介绍了C:为什么此服务器/客户端设置只能在一台计算机上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是网络新手,我想知道为什么 C中的TCP Server-Client实施只能在一台计算机上工作吗?(1)

I'm new to networks and I'm wondering why this TCP Server-Client implementation in C only works on one computer? (1)

我的意思是我必须为服务器程序打开一个终端,为客户端程序打开另一个终端.但是,为什么这在计算机之间不起作用?在一台计算机上启动服务器程序,在另一台计算机上启动客户端程序.

I mean I have to open one terminal for the server program and another one for the client program. But why this doesn't work between computers? Starting the server program on one computer and the client program on another computer.

我们如何修改代码才能在计算机之间工作?(2)

How we need to modify the code to work between computers? (2)

关于整个主题,什么是伟大的资源?(3)

And what are great resources to start on the whole topic? (3)

推荐答案

它将在其他计算机上运行.只需确保您执行以下操作即可:

It will work on other computers. Just ensure you do the followings:

  1. 两台计算机处于网络中,并且可以通过PING互相查看
  2. 使用服务器计算机的IP在客户端程序中更改 127.0.0.1
  3. 使用服务器计算机的 netstat 检查侦听端口,并确保端口8080处于侦听模式
  4. 确保服务器计算机中没有防火墙,可以在客户端计算机中使用 telnet 以确保服务器上的端口可访问.
  1. Two computer be on a network and see each other with PING
  2. Change 127.0.0.1 in client program with the IP of the server machine
  3. Check listening ports with netstat of server machine and Make sure the port 8080 is in Listening mode
  4. Make sure there is no firewall in server machine, you can use telnet in client machine to make sure port on the server is accessible.

在测试C程序之前,请确保第三方应用程序在服务器之间的通信正常.例如,通过端口2000上的 ncat -l 2000 -k -c'xargs -n1 echo'在Linux中创建回显服务器.

Before test your C program, make sure the communication is OK between servers by third party application. For example, make an echo server in linux by ncat -l 2000 -k -c 'xargs -n1 echo' on port 2000.

强烈建议将端口从8080更改为另一个(例如8192).8080与某些第三方应用程序一起使用.

It highly recommended change Port from 8080 to another one (for example 8192). 8080 is used with some third party applications.

这篇关于C:为什么此服务器/客户端设置只能在一台计算机上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆