简体   繁体   English

通过以太网电缆将客户端PC连接到服务器PC? (Java)的

[英]Connecting a client pc to a server pc via an ethernet cable? (java)

Currently the setup I have is the client code is on my laptop, which is hooked up to an embedded box PC which will run the server code. 目前,我的设置是在笔记本电脑上安装客户端代码,该笔记本计算机已连接到将运行服务器代码的嵌入式Box PC。

I've tested the client/server interaction running both the client code and server code on my laptop, and can confirm they run together. 我已经测试了在笔记本电脑上同时运行客户端代码和服务器代码的客户端/服务器交互,并可以确认它们一起运行。 However I'm stuck as how to proceed and adapt my code from what it is now. 但是,我对如何继续进行修改以及适应现在的代码感到困惑。 If I understand correctly, the Server sets up an IP address and the client looks for it and connects to it? 如果我理解正确,则服务器会设置IP地址,客户端会寻找并连接到它?

Currently this the code I have converted to on the sever side (The commented out section is what was in place when I was running it on my laptop) 目前,这是我在服务器端转换为的代码(注释掉的部分是我在笔记本电脑上运行它时的位置)

InetAddress ip = InetAddress.getByName(ipAddress); 
server = new ServerSocket(SOCKET_PORT, 1, ip); //SOCKET_PORT = 8010

//server = new ServerSocket(SOCKET_PORT); //SOCKET_PORT = 8010

Would this be considered to be the right way to go about doing things on the server side? 是否认为这是在服务器端执行操作的正确方法?

As for the client I'm still quite confused.. so far this is the code I had implemented for when I had the code ruinning on the same device... 至于客户端,我还是很困惑。.到目前为止,这是我在同一设备上破坏代码时实现的代码...

(I have a loop that spins off clients into separate threads when they connect to the server) (我有一个循环,当客户端连接到服务器时,它将客户端分解为单独的线程)

//Socket clientSocket = new Socket("localhost", port);

And then here is the code I think it will convert to, but I may be wrong here 这是我认为它将转换为的代码,但是我在这里可能是错误的

Socket clientSocket = new Socket(ipAddress, port);

I appreciate any help, even if it's just helping to describe the general process of an IP connection between server/client on different devices 我很感谢您的帮助,即使只是帮助描述不同设备上服务器/客户端之间IP连接的一般过程

我认为您只需连接设备,查找IP(可能使用命令行)并用这些IP替换IP地址即可。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM