Recently, a server-side program was written with a socket, listening on 1024 ports , detecting requests from clients, and writing start-up and stop scripts in Linux:
In Eclipse Java write a program, right-click the export generated Runnable JAR file and then Socketserver.jar upload to the server.
1. Start startup.sh
# ----------------------------------------------------# Start Script forThe socekt server#----------------------------------------------------PS-ef |grep Socketserver.jar |grep-v grepif[$?-eq 0];then Echo' Socket server is running! 'Elsenetstat-APN |grep 1024if[$?-eq 0];then pid_1024= $ (echo ' netstat-apn |grep 1024x768 | awk ' {print $NF} ' |awk-f '/' {print '} '') Kill $PID _1024 Fi echo"Startup Socket Server:"nohup Java-jar Socketserver.jar &fi
2. Start shutdown.sh
#----------------------------------------------------for---------------------------- -------------------------ef | grep Socketserver | grep-v grepif [$?-eq 0 ];then pid_1024=$ (Echo ' netstat-apn |grep 1024x768 | awk ' {print $NF } ' |awk-f '/' {print '} ' ) kill $PID _1024 else' not found Socket pid! ' fi
at the same time, set the file operation permissions: chmod 777 startup.sh, chmod 777 shutdown.sh
The last execution./startup.sh can be started!
Linux in startup.sh and shutdown.sh