0

我制作了一个客户端服务器程序,可以将文件从我的 android 设备发送到我的 windows 7,服务器端程序 (windows) 侦听循环并对套接​​字的接收做出反应。

所以我将我的 java 程序导出到 jar 文件并执行以下命令(以管理员身份打开 cmd 后)以使其成为服务:

prunsrv //IS//Colisage --DisplayName="Colisage" --Description="Colisage" --Install="C:\Pda\prunsrv.exe" --Jvm="C:\Program Files\Java\jdk1.8.0_161\jre\bin\server\jvm.dll" --StartMode=jvm --StopMode=jvm --Startup=auto* --Classpath="C:\Pda\colisage.jar" --LogLevel=DEBUG^ --LogPath="%cd%\logs" --LogPrefix=procrun.log --StdOutput="%cd%\logs\stdout.log" --StdError="%cd%\logs\stderr.log"

该服务已正确创建和执行。

这是 procrun.log 文件显示的内容:

[2018-06-07 16:04:12] [debug] ( prunsrv.c:1729) [ 3708] Commons Daemon procrun log initialized
[2018-06-07 16:04:12] [info]  ( prunsrv.c:1733) [ 3708] Commons Daemon procrun (1.1.0.0 64-bit) started
[2018-06-07 16:04:12] [debug] ( prunsrv.c:602 ) [ 3708] Installing service...
[2018-06-07 16:04:12] [info]  ( prunsrv.c:641 ) [ 3708] Service Colisage name Colisage
[2018-06-07 16:04:12] [debug] ( prunsrv.c:657 ) [ 3708] Setting service description Colisage
[2018-06-07 16:04:12] [info]  ( prunsrv.c:675 ) [ 3708] Service 'Colisage' installed
[2018-06-07 16:04:12] [info]  ( prunsrv.c:1814) [ 3708] Commons Daemon procrun finished
[2018-06-07 16:04:53] [debug] ( prunsrv.c:1729) [ 2116] Commons Daemon procrun log initialized
[2018-06-07 16:04:53] [info]  ( prunsrv.c:1733) [ 2116] Commons Daemon procrun (1.1.0.0 64-bit) started
[2018-06-07 16:04:53] [info]  ( prunsrv.c:1643) [ 2116] Running 'Colisage' Service...
[2018-06-07 16:04:53] [debug] ( prunsrv.c:1417) [ 1120] Inside ServiceMain...
[2018-06-07 16:04:53] [debug] ( prunsrv.c:885 ) [ 1120] reportServiceStatusE: dwCurrentState = 2, dwWin32ExitCode = 0, dwWaitHint = 3000, dwServiceSpecificExitCode = 0
[2018-06-07 16:04:53] [info]  ( prunsrv.c:1175) [ 1120] Starting service...
[2018-06-07 16:04:53] [debug] ( javajni.c:236 ) [ 1120] loading jvm 'C:\Program Files\Java\jdk1.8.0_161\jre\bin\server\jvm.dll'
[2018-06-07 16:04:53] [debug] ( javajni.c:753 ) [ 4208] Jvm Option[0] -Djava.class.path=C:\Pda\colisage.jar
[2018-06-07 16:04:53] [debug] ( javajni.c:753 ) [ 4208] Jvm Option[1] exit
[2018-06-07 16:04:53] [debug] ( javajni.c:753 ) [ 4208] Jvm Option[2] abort
[2018-06-07 16:04:53] [debug] ( javajni.c:990 ) [ 4208] Java Worker thread started Main:main
[2018-06-07 16:04:54] [debug] ( prunsrv.c:1235) [ 1120] Java started Main
[2018-06-07 16:04:54] [info]  ( prunsrv.c:1333) [ 1120] Service started in 1284 ms.
[2018-06-07 16:04:54] [debug] ( prunsrv.c:885 ) [ 1120] reportServiceStatusE: dwCurrentState = 4, dwWin32ExitCode = 0, dwWaitHint = 0, dwServiceSpecificExitCode = 0
[2018-06-07 16:04:54] [debug] ( prunsrv.c:1572) [ 1120] Waiting for worker to finish...

stdout.log 文件:

connection attempt ..
successfully connected
waiting on port 11845 ...

什么对应于应该在开始时显示我的程序,这里是我们感兴趣的 java 程序部分:

System.out.println ("waiting on port" + String.valueOf (port) + "...");
clientSocket = serverSocket.accept ();
System.out.println ("Receiving the request");

总而言之,当我在 eclipse 或 jar 上运行我的 java 程序时,它运行完全并正确接收文件,而我的服务仅执行开始,它不接收套接字。

预先感谢您的帮助

4

1 回答 1

0

问题解决了,那只是因为防火墙

于 2018-06-08T12:15:44.460 回答