Establish a simple C / S structure TCP / IP service with Socket
Java, Socket, TCP / IP, Network Programming
Environment: Windows Server 2003
Users can also write simple TCP / IP services
/ * As a Server Establishing a Read Write Binary Service * / Import Java.io. *; Import Java.Net. *; Public Class Daytimeserver {Serversocket Sock; Public Daytimeserver () {Try {Sock = New ServerSocket (37);} catch (IOEXCEPTION E) {system.err.println (e); System.exit (1);}} protected void renservice ()} {socket iOS = NULL; DataOutputStream OS = NULL; while (true) {{os = sock. Accept (); ostem.rr.println (ios.Getinetaddress (). getHostName ()); os = new dataputstream (ios.getoutputstream ()); long time = system.currenttimemillis () (); long distance = (long) (( (1970-1900) * 365.25) -1 .5); long sec = distance * 24 * 60 * 60; time / = 1000; time = sec; os.writeint (int) Time); Os.close );} Catch (ioException e) {system.err.println (e);}}} public static void main (String [] args) {new daytimeserver (). RENSERVICE ();}}