Windows 上的 PPP 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7011384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:47:47  来源:igfitidea点击:

PPP Server on Windows

javawindowstcpppp

提问by Marius Reppe

We have a solution where some hardware connects to a COM port on a Win 7 machine, and interacts with our Java app. The hardware wants to use a PPP Server to transparently connect to an other server over TCP/IP.

我们有一个解决方案,其中一些硬件连接到 Win 7 机器上的 COM 端口,并与我们的 Java 应用程序交互。硬件希望使用 PPP 服务器通过 TCP/IP 透明地连接到其他服务器。

Does anyone have a suggestion on how to do this? Start an OS native PPP Server from the Java app, with a connection to the COM port? How is this done?

有没有人有关于如何做到这一点的建议?从 Java 应用程序启动 OS 本机 PPP 服务器,并连接到 COM 端口?这是怎么做的?

回答by Michael Burr

You may be surprised to find that Win7 still supports PPP natively.

你可能会惊讶地发现 Win7 仍然原生支持 PPP。

Follow these steps (or something like them) and you should be mostly good to go. I haven't actually performed a PPP connection since probably Win98, maybe Win2k, but the steps look to be pretty similar to what they were back them. It's not straightforward, but these should get you 80 or 90% of the way (the last 10-20% will be the normal hair-pulling irritations of getting the serial connection properly configured - there are way too many options involved in serial communications and PPP for it to go right on the first connection attempt).

遵循这些步骤(或类似的步骤),您应该可以顺利进行。我实际上没有执行过 PPP 连接,因为可能是 Win98,也可能是 Win2k,但是这些步骤看起来与他们支持的步骤非常相似。这并不简单,但是这些应该可以让您完成 80% 或 90% 的工作(最后 10-20% 将是正确配置串行连接的正常情况——串行通信涉及的选项太多, PPP 使其在第一次连接尝试时正确运行)。

  • Open Control Panel
  • Select "Phone and Modem". If it asks you about location, type in whatever information you need to make that dialog box happy (I think it just needs your area code, but maybe not, or maybe other stuff - it doesn't matter we won't be using it).
  • Tell it you want to install a modem, and don't worry that if can't find one - you'll be selecting one from a list.
  • Click the "Add" button, and tell it not to bother detecting one automatically
  • Under "(Standard Modem Types)" select the "Communications cable between two computers"
  • tell it what serial port to use
  • 打开控制面板
  • 选择“电话和调制解调器”。如果它询问您位置,请输入您需要的任何信息以使该对话框满意(我认为它只需要您的区号,但也许不需要,或者其他东西 - 没关系我们不会使用它)。
  • 告诉它你想安装一个调制解调器,不要担心如果找不到 - 你会从列表中选择一个。
  • 单击“添加”按钮,并告诉它不要自动检测一个
  • 在“(标准调制解调器类型)”下选择“两台计算机之间的通信电缆”
  • 告诉它使用什么串口

Now you need to set up the 'network adapter' for the PPP connection

现在您需要为 PPP 连接设置“网络适配器”

  • go to the "Network and Sharing Center" of Control Panel
  • Click on "Set up a new connection or network"
  • Select "Set up a dial-up connection"
  • If it asks you about what modem to use, select the "Communications cable between two computers modem" that you just set up (this shouldn't happen unless you have an actual modem in your computer).
  • Give the "Create a Dial-up Connection" dialog box a bogus phone number so it will let you continue... And give it a connection name that you like instead of "Dial-up Connection"
  • Click "Connect" and it'll try to dial. Of course it'll fail. Click "Set up the connection anyway"
  • 转到控制面板的“网络和共享中心”
  • 点击“设置新的连接或网络”
  • 选择“设置拨号连接”
  • 如果它询问您要使用哪种调制解调器,请选择您刚刚设置的“两台计算机调制解调器之间的通信电缆”(除非您的计算机中有实际的调制解调器,否则不会发生这种情况)。
  • 给“创建拨号连接”对话框一个虚假的电话号码,这样它就可以让你继续......并给它一个你喜欢的连接名称而不是“拨号连接”
  • 单击“连接”,它会尝试拨号。当然会失败。点击“仍然设置连接”

Now configure various PPP settings on the new network adapter:

现在在新的网络适配器上配置各种 PPP 设置:

  • Click on the "change adapter setting" link in the "Network and Sharing Center" control panel
  • Right click on the network adapter that you just created ("Dial-up Connection" or whatever name you gave it), and select "Properties"
  • Configure the "Communications cable between two computers" (mainly this lets you set the speed). Look through the other tabs for the various other options you might need to control. Don't forget to configure the TCP/IPv4 properties that you might need on the "Networking" tab. If you're using IPv6, make sure that stuff is configured too.
  • 单击“网络和共享中心”控制面板中的“更改适配器设置”链接
  • 右键单击您刚刚创建的网络适配器(“拨号连接”或您给它起的任何名称),然后选择“属性”
  • 配置“两台计算机之间的通信电缆”(主要是让您设置速度)。查看其他选项卡,了解您可能需要控制的各种其他选项。不要忘记在“网络”选项卡上配置您可能需要的 TCP/IPv4 属性。如果您使用的是 IPv6,请确保也配置了这些内容。

Once the hardware device establishes a PPP connection to the Win7 COM port, the Java application should be able to communicate over the PPP link as if it were a regular network adapter. Good Luck!

一旦硬件设备与 Win7 COM 端口建立了 PPP 连接,Java 应用程序就应该能够通过 PPP 链接进行通信,就像它是一个普通的网络适配器一样。祝你好运!

回答by mico

Using Google on the basis of @hari comment about javax.commI found a tutorial on TINI, which may be useful on your purposes: the guide takes a PPP connection through COM port with TINI library equally as you want to do.

在@hari 评论的基础上使用谷歌javax.comm我找到了一个关于 TINI 的教程,这可能对您有用:该指南通过 COM 端口与 TINI 库建立 PPP 连接,与您想做的一样。

回答by JaeMann Yeh

This is a workaround using VirtualBox. I can't figure out how to run PPP server natively on Win7.

这是使用 VirtualBox 的解决方法。我不知道如何在 Win7 上本地运行 PPP 服务器。

pppd - Ubuntu ttyS0 - VirtualBox Port 1 - Win7 COM1 -- RS232 -- target's ppp client

pppd - Ubuntu ttyS0 - VirtualBox Port 1 - Win7 COM1 -- RS232 -- 目标的 ppp 客户端

  1. Prepare VirtualBox 5 and Ubuntu 16 as a guest OS on Win7
  2. Go to the VirtualBox Settings -> Serial Ports -> Port 1
    • Check : Enable Serial Port
    • Port Number : COM1 IRQ : 4 I/O Port : 0x3F8
    • Port Mode : Host Device
    • Check : Connect to existing pipe/socket
    • Path/Address : COM1
  3. Open a Ubuntu terminal

    • sudo apt-config install ppp
    • sudo apt-get install ppp
    • sudo stty -F /dev/ttyS0 raw
    • sudo stty -F /dev/ttyS0 -a
    • sudo pppd /dev/ttyS0 115200 192.168.17.1:192.168.17.2 proxyarp local noauth nodetach dump nocrtscts passive persist maxfail 0 holdoff 1

    pppd options in effect:
    nodetach # (from command line)
    holdoff 1 # (from command line)
    persist # (from command line)
    maxfail 0 # (from command line)
    dump # (from command line)
    noauth # (from command line)
    /dev/ttyS0 # (from command line)
    115200 # (from command line)
    lock # (from /etc/ppp/options)
    nocrtscts # (from command line)
    local # (from command line)
    asyncmap 0 # (from /etc/ppp/options)
    passive # (from command line)
    lcp-echo-failure 4 # (from /etc/ppp/options)
    lcp-echo-interval 30 # (from /etc/ppp/options)
    hide-password # (from /etc/ppp/options)
    proxyarp # (from command line)
    192.168.17.1:192.168.17.2 # (from command line)
    noipx # (from /etc/ppp/options)
    Using interface ppp0
    Connect: ppp0 <--> /dev/ttyS0
    Cannot determine ethernet address for proxy ARP
    local IP address 192.168.17.1
    remote IP address 192.168.17.2

  1. 准备 VirtualBox 5 和 Ubuntu 16 作为 Win7 上的来宾操作系统
  2. 转到 VirtualBox 设置 -> 串行端口 -> 端口 1
    • 检查:启用串行端口
    • 端口号:COM1 IRQ:4 I/O 端口:0x3F8
    • 端口模式:主机设备
    • 检查:连接到现有的管道/套接字
    • 路径/地址:COM1
  3. 打开一个 Ubuntu 终端

    • sudo apt-config 安装 ppp
    • sudo apt-get install ppp
    • 须藤 stty -F /dev/ttyS0 原始
    • 须藤 stty -F /dev/ttyS0 -a
    • sudo pppd /dev/ttyS0 115200 192.168.17.1:192.168.17.2 proxyarp 本地 noauth nodetach dump nocrtscts 被动持久 maxfail 0 延迟 1

    有效的 pppd 选项:
    nodetach # (from command line)
    holdoff 1 # (from command line)
    persist # (from command line)
    maxfail 0 # (from command line)
    dump # (from command line)
    noauth # (from command line)
    / dev/ttyS0 # (来自命令行)
    115200 # (来自命令行)
    lock # (来自 /etc/ppp/options)
    nocrtscts # (来自命令行)
    local # (来自命令行)
    asyncmap 0 # (来自 /etc/ppp /options)
    被动 # (来自命令行)
    lcp-echo-failure 4 # (来自 /etc/ppp/options)
    lcp-echo-interval 30 # (来自 /etc/ppp/options)
    hide-password # (from /etc/ppp/options)
    proxyarp # (from command line)
    192.168.17.1:192.168.17.2 # (from command line)
    noipx # (from /etc/ppp/options)
    使用接口 ppp0
    Connect: ppp0 <--> /dev/ttyS0
    无法确定代理 ARP
    本地 IP 地址 192.168.17.1
    远程 IP 地址 192.168.17.2 的 以太网地址