有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java服务器socket是执行此操作的最佳选项

我怀疑该用什么来做这件事:

我想有一个新家。bat文件(该文件将在计算机上打开,通过该bat,我将能够从我的应用程序中获取事件日志,并通过它运行例程,如“保存备份”)。 我的登录系统只有在这样的情况下才能工作。bat文件已打开 类似于“游戏服务器”的东西(我不知道这是否必要,但我想这样做是为了培训)

我曾想过在数据库中创建一个辅助表,其中只有2个字段id/一个布尔字段

当你打开这个。bat将建立连接并将该值设置为1

在我的登录系统中,我会检查这个值是否为1,然后我可以释放登录

我不知道这是不是最好的办法

或者在这种情况下,使用serversocket会更好吗

有人能给我举个例子,说明我该如何开始吗


共 (1) 个答案

  1. # 1 楼答案

    对于您想要的,您不需要服务器套接字。我发布了那个链接,所以你可以理解它是什么。将事件记录到文件中,您只需要对文件的读/写有基本的了解。这个蝙蝠延伸并不重要。但是如果你想要你的。bat要作为批处理命令从命令行执行,则该文件需要是有效的批处理脚本

    你必须问自己的问题是:“谁将连接到你的服务器?如何连接?”然后你才能确定你真正需要什么

    服务器套接字用于实时通信:

    Normally, a server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request.

    On the client-side: The client knows the hostname of the machine on which the server is running and the port number on which the server is listening. To make a connection request, the client tries to rendezvous with the server on the server's machine and port. The client also needs to identify itself to the server so it binds to a local port number that it will use during this connection. This is usually assigned by the system.

    这来自:https://docs.oracle.com/javase/tutorial/networking/sockets/definition.html

    如果连接,将值从0更改为1,如果未连接,将值从1更改为0,这就像将首选项保存到文件中一样。你所需要知道的就是如何操作文件