Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
server.txt

server.txt

Ratings: (0)|Views: 28|Likes:
Published by Will Jay Z
How to create simple chat server application in CLI using java
How to create simple chat server application in CLI using java

More info:

Published by: Will Jay Z on Jan 08, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

01/08/2013

pdf

text

original

 
import java.io.*;import java.net.*;import java.util.*;public class Server{private static ServerSocket servSock;private static final int PORT = 1234; public static void main(String[] args){System.out.println("opening port...\n");try{servSock = new ServerSocket (PORT);}catch (IOException ioEx){System.out.println("Unable to attach to port!");System.exit(1);}do{handleClient();}while (true);} private static void handleClient(){Socket link = null; try{link = servSock.accept(); Scanner input =new Scanner(link.getInputStream());PrintWriter output =new PrintWriter(link.getOutputStream(),true); int numMessages = 0;String message = input.nextLine();while (!message.equals("***CLOSE***")){System.out.println("Message received.");numMessages++;output.println("Message " + numMessages+ ": " + message);message = input.nextLine();}output.println(numMessages+ " messages received.");}catch(IOException ioEx){ioEx.printStackTrace();} 

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->