Java Sockets over WLAN?

北城余情 提交于 2019-12-11 07:36:52

问题


I have 2 windows PC's connected over an ad-hoc wlan network.
Using this existing connection can I communicate between these pc's via sockets?
Can I open a server socket on one pc and make the other pc a client and connect to the other pc and then send and receive data over this connection?
Do I need a specific api for this or can I just use java.net.Socket and java.net.ServerSocket?


回答1:


Of course you can. There is an IP network over the WLAN connection, and nothing stops you from establinshing TCP connection.

As far as sockets are concerned this is no different to a wired (Ethernet) connection, the difference ends at Data-Link layer




回答2:


Of course you can use (Server)Sockets. Sockets are a concept of the TCP-protocol (OSI-layer 4), which operates on top of the IP-protocol (OSI-layer 3), which itself operates on top of WLAN or Ethernet (OSI-layer 2), which operates on a physical link (radio waves for WLAN, ethernet cables for ethernet).

The Implementations of the OSI-layers are replaceable (or better: should be replaceable). So it doesn't matter if you are using WLAN, ethernet or something else, as long as you don't go below layer 3 (which isn't possible with Java anyway).

Have a look at the Wikipedia article for more information



来源:https://stackoverflow.com/questions/1824495/java-sockets-over-wlan

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!