multithreading - How to create a basic Java Server? -


Basically I want a basic Java server that can be connected to a lot of people and when connected clients (already Only coded in the obiege) -a) Sends data to it, sends it back to everyone sent it back.

I am a real Java novice and I do not need Java for future to do anything, but this is so much that I want to get it out as soon as possible rather than learn Java from scratch Want to So if someone has some source code for this or maybe a tutorial, then it will be appreciated.

thanks :) Ozzie

A simple "knock knock" server here Courtesy:

  Import java.net *; Import java.io * *; Public class KnockKnockServer {Public Static Zero Main (string [] args throws IOException {ServerSocket serverSocket = null; {ServerSocket = new ServerSocket (4444); } Hold (IOException e) {System.err.println ("Could not listen on port: 4444."); System.exit (1); } Socket client socket = empty; {ClientSocket = serverSocket.accept (); } Hold (IOException e) {System.err.println ("accept accept."); System.exit (1); } PrintWriter = Out New Print Writer (clientSocket.getOutputStream (), true); BufferedReader = New in BufferedReader (New InputStreamReader (clientSocket.getInputStream ())); String input line, outputline; KnockKnockProtocol kkp = New Knockcon Protocol (); OutputLine = kkp.processInput (null); Out.println (outputLine); While ((inputLine = in.readline ()) = null) {outputLine = kkp.processInput (inputLine); Out.println (outputLine); If break (outputLine.equals ("by.")); } Out.close (); In.close (); ClientSocket.close (); ServerSocket.close (); }}  

You can not be simpler than this


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -