!"# $ %!&' # &! ())*!$

Size: px
Start display at page:

Download "!"# $ %!&' # &! ())*!$"

Transcription

1 !"# $ %!&' # &! ())*!$

2

3 !" #!$ %& ' ( ) * +,--!&"" $.!! /+010!"

4 +!, 31! 4)&/0! $ #"5!! & + 6+ " /&8-9%& ( +" 5)& /*#.! &( $ 1(" 5 # ( # + 7$ (+!98 +&%& ( +!" (!+!/ (! (! 7 1+1( & + ":! " (&, 71( $ $ 1( 0" 5;<=>/ &&! 1"A!070$ 1! $0&7 B & + " 1& 0"&7$ +1 &&70$ &&$1 &" 71( + 1( $"C $ 0/ & +" 2

5 (!(!/0&1&2 E( 7 " 0 = ("5 0+!( * (.0 " (01 7 ( & ( " 5 & +! *9." *8.+0 +" 7&"";""""+ & (" 5F'8=<;/ !1" 5 $! 1 (1+" 5! 9&2 0G 27(1" 5 1 ( 1 1 " D

6 590 + " (1& 70$ 1! 1& "5 &0$ 7 $ & +" " " 8 & 70$ +"&!& "9 7 0( $1&7" 5 8/ F'8 =</ 0 " 8! ( 7 0( 0 " 1! & "#! $ (" 5+& 1 & $+ 1 " 3$+1( 4*+"0+1. " : / $ (" 5>E /; &7 (" & $+ 1 IJ 7 4! ((" " $0 " & &7, 5K/,?LM?NOP K5/, 58?NOP?LM?NOL 5K/, 58?NOL 5" 0$ + (0 0" H

7 85 8K?NO;2?LM?NO58O;D?LM58?NO;D58O258!" & +1 " 8! 0 0 & & $ ( 1 &"5 1 1 $&" & 0 '9M &!" 0,70! & 1 0(0+!+1 +1"5 $ ( +1 77! $ " # $%& 59/1+7 +C3/ +8/!"C3/+!"#*3M?. 0 7& &91 "8+ $ *'./ 9:5.&QQQ *#." (!*!/ 3 5 $ $! +1 (+&((!$"5%& &!1/+!1" C G 0$ 1(*98.&( $ 1( &+ =

8 & 1/ " 5 1/ 1!$B $ & ( " 5 1/+ + E &!" $ ( *&. B*.+77 & " 5 & &! 0$( " & 1/! ( *+.! 10&&!&7"5! 1/! & & & 1 1/ 1& $ $ 1(" $ 0 " 0 " 51&/ & "# $ & 1 +!&70!0 " 0 & 1! 1/! $ 1( $ 1( ( 0 1 &! 1 0" & & + $ ++ &" (! 1 & " 3+ *+"C3.! 01/+$ 0"1(0 " #$ '$?1/ 0 ( +1 $ + " 5 7 ( 1 0 $ " 9 & + G+1 ( 1 " 5 1/ ( (0 (+ 1 "! 0 +&(!( + 1((!(" 5 ( 47 & &$ + (+1(07$ " ( ( & ( R

9 + +" 8/ &! * + ". (!4!/-.5 &3 5#+ 7& &9 " 7 &(! #->"< & " # 0& #-;">! F'8 H;H/ F'8 H;=/ 0! & &7 #-;"; & " 5 + &0 + " 5 + ( &! " :& ( +1 + &( * " 0/$+G. 1 & + /0&" 5+E&+"5+&7 E&& 4 #/ ( 4 &( ( "5 1(,+10+ $ #&&"5+1 0! &0!77+" 0 ( 7I?+J! " 5#7, 5#+ 170 #0!1 " 0! +,! "# $%&'"'( % )$$# )****( +,- ).$$*"/ *"'3#,%+3)'"*56//7'//8( - ) 9 9$$ 9$$ 9# $:9$ 9 # $3;</"= 9 -,A )#, 3;</"*( -,)$ ( -,B# E,-$)7//( B ),$( <

10 ( 5 S! & ($! " Q ) 8FTA' C G + A'" 5 0!/! & " " 5 7 # + 1! $! & 70" -$1- U11" 0"5 (#-;";! +#;";&(!&" 5&7/0!1 01( 7"5F'8H;H/ 2< 0!1& 0 &"+ +7, '!1 # C/ % 570 / (!+!"G& 0 " 5 *! 7.!" 5 0 +$B IVOJ +$ +0 " 511+/A $ 50 &07" 511+/ 1 50(+0$"$I+J! +/+$ $ $ " 511+/8 +/5& " 8 #-;";/ "9! >>+(! & / &! &$ +1 " 5 0!1 +10! &! &7+G& " 5#&7, /&($ W0!1 W 5& +$&7, %&'"'6//DE( F )C 6GD 6//7'*)*6)'6.( C).1HC"/"6( B,A #)>/( B,) 9 # $( ( I# $JI#JI $J( %$$I $JI#J( IHJ%$$IHJI# $J( ;>

11 5& #&(! & 7"!7 ($(&&&"&&0!1 &+( &" 5 0!1! &" R ( & +7 1 & *+"+&(". 5 0!10, '!1?& 8 /A 8 /+ % 5& (&!" 5&!/ " 5+$" 5# &7/ & 0& 4, & " ($) $ 5 # 7 $ +1 0+&$"5 %&'#!&0 $ & +1 "5% /$ &! +1" 5 4 & )& +!$ $ $ " *!/" 5%& & +&7 (/!&" 1!" A 7 & /+ / +1 ;;

12 " %&! 8 +! /+$ 1(&(" 5%& & +8-9 (+1 1/!$+ 1(!0K?3 1/! " *!+!637 5 %&/ 1/ &( 0 7 K?3 1 01/ 0 "?1/(#))&+ & $ " 5$ 1(%&07 (/&(($& &(!$ "! 7 1 & 4&" 5 $ 1( 0!& (#))& ($& 1/ "?& 1 (#))#& $ $+! 1/&!$ " serversocket = new ServerSocket(4444); catch (IOException e) { System.out.println("Could not listen on port: 4444"); System.exit(-1); & ( & ($ $$ 0 " "" + 07 &! 1, Socket clientsocket = null; clientsocket = serversocket.accept(); catch (IOException e) { System.out.println("Accept failed: 4444"); System.exit(-1); C3 1 &!$ 7 $ 1( %& (#))!*&(#))!+&&" 5 $ 1( + $ &!$" A 7 1 "!& $ 1( 0 7 (,) 5 -+ ($ ;

13 !"! ( & ( / 0 +$00 " C3 G 7 & 0 ( 1!" 5.#))&&#&+ 1(! +( / & + &(( "!$+ ( * &!$(. *101.&!" 4!/.38 5 #-;"; 0+ $ 1 +!$"?4)&0+ 1"5& " 5+&7 + 0$!$ G 0 ( & +$00 " 7 ( 7 $ $!&"? & D (" + &7, Q&, ?&,$! ++ & :, 01(0++1( Q1 3, &47$/1 $&(! 8 0,)& 0$ (+ 4!+!/039 5 &40+4"8!0++1 " 8$+ $ + + ;

14 +!( 7" " & " # ($" 5 +" ($ 0++1!&" 4!*!/ )& 0$ (+ "? $ $0/#)0& +0" 5 )&" & 0" 5 )& 0$1(! $!, &( ($ & *+" && & 1 &$ + B )&" & (& ". 0 0$0 &("5/ 4 " 5 & $ 07 +/0$"X!! 0/ & 70 &!$*+"!." M G!Y 5 )&" 0& (, K9B #9 H $ 9B <GL 5+(, if (templine.touppercase().startswith("maxconnections")){ int index=templine.lastindexof("="); buffersize=integer.parseint(templine.substring(index+1)); catch (Exception ex){ System.out.println("Config(): Set maxconnections to "+buffersize); 5$00?&( 7 +! 0$ +" IOJ!$ & &" 58 0 $ 7& 7! +, ;2

15 A 5 & & "5& & &" G8 1 5G " 6+ 1 #!& : +1 & ( "#7!$" $00? 570 +$00" 5+0 $ " 4!*!/: ($+++!!"5 ($$ $&(($*(!$+!!.4 + "Z ($(+ " public static void main(string args[]) { WebServer myserver=new WebServer(); myserver.serve(args); 5#++01($&& 1"5+ $ & +! " 5 + $ $+ 0 7, $ +<>>>/++" 5 ($ +! + &( $ &)& 0$1(!"5+ $!#&' *& 0$. + " 1/ $ 0 1! !" ServerSocket srvr = new ServerSocket(port); System.out.println( "Serving requests on port "+port+"..." ); Socket tempclientsocket; (# *+ 5 $!$ $ %& +"5";"+!&7+1( ;D

16 ($ && $$ 0 " ($ & +! + 0$& 7 1 & 0$ + "! + 1!&7)& 10" 0$ & +$ (&!(& &0$( +" &$ & + & 8C 7+$ "Z (& & " A $ # 2 +$!$ & ( $ &(!$" ServerThread tempthread; while( true ) { if (ConnectionManager.getNrOfConnections()<Config.maxConnections){ tempclientsocket = srvr.accept(); tempthread=new ServerThread (tempclientsocket); System.out.println("Accepting connection, this is nr. "+ConnectionManager.getNrOfConnections()); ConnectionManager.addConnection(); tempthread.start(); else{ System.out.println("Error: too many connections, denying request."); / 0$1( G +1" 5 ($ 1 0 1!& & # 2 + +!$ "5+1 &!!!($ &!$" '! 7 0$ 0$ "5%&7!7(&! +! 70$"5 &$ # 2 (!!$+ 0" 5 ( (" ;H

17 4!4!6"2 5 $ & 1 & ( 0 1! 7 3 +$!$ " + # & / " 5 &(*5 (!$., ($ 0$ %& 7! &! 0$ (" 7 7! #:A! &" %& / 7 &! 4 " " 7!$ $ " outtoserver = new PrintStream(clientSocket.getOutputStream() ); infromserver = new BufferedReader(new InputStreamReader( clientsocket.getinputstream())); 5 & +,, & +, ($ 17 $( & 7 0 &(( / &" 5 /4!$(+ (!$ $ "1 $47/1 $ &! / 47 I $J /0$ $ $! &B+" ($ & ( / 4, #))))) &" 5 / 47 I $ J 0 &( & & +$00 &(" $ / &$ $#-($ &&"5-E ( ( ($ & 0$(&! &( + " + 1 $ ( & " 5 & &$ "'! 1 & & 0!1(B $ 7& " 5 7.#),)+ & &!$" 5 7! IJ &!$#*($B F'8 H;H! I2>> K FV$J $ $ & 456,($" ;=

18 5 & ($ & $ *& ( &( 0.0!7 1 (" ((,-.,/0 5 ($ 7 + &$ 7 70 (!! &&& 7 +/ " 1 $& " M 7 & I511+/ 1 J/I+J! I+BVO>J! +0!&" for (int i=0; i<requests.size();i++){ if ((requests.get(i).tostring().touppercase().startswith("accept- ENCODING")) && (requests.get(i).tostring().touppercase().indexof("gzip")!=-1)) { clientsupportsgzip = true; if ((requests.get(i).tostring().touppercase().indexof("gzip;q=0.") ==-1) && (requests.get(i).tostring().touppercase().indexof ("GZIP;Q=0")!=-1)){ clientsupportsgzip = false; 57D"+ 7& 01(" &7!$ +70/!&!&0!1, $ $ &! & +$" 5 4 &1#:A0/$ IG- J+$ +$ " infile=new FileInputStream(requestedFile); outtoserver.print("http/ OK\r\n"); currentdate=new Date(); outtoserver.print("date: "+currentdate.togmtstring()+"\r\n"); outtoserver.print("server: Mini WebServer v."+config.version+"\r\n"); outtoserver.print("content-type: text/html\r\n"); 5 70& +$00 &&" 4!$ ($ && 0! ( ;R

19 *8FTA'A'.70$ 70($ (! &(" 5 +$00 + ( &$ $ +$ 7 ( " 5 $) ($ & &$ 0/ (!& 1!" byte [] buffer = new byte[config.buffersize]; try{ int numbytes = infile.read(buffer, 0, Config.bufferSize); while (numbytes!= -1) { outtoserver.write(buffer, 0, numbytes); numbytes = infile.read(buffer, 0, Config.bufferSize); 5%&&4 7!& 4"# 0 $"$,7&( 7 2 &! I2>2E'M'$ J " 5?& &($ " 1 &! 8 1 : # ($ && 1 & & +1 " 5 & ($ (Q1 3 &!" 4!;!/:3"%3"# 5 & 4 70$ ( &*+" 8+1 (1&." (&(+7& ( & & $" X 70 +$ IJ +1 & G 0 ( +1 " G +1 IJ + +1!+1 0 $ " 5+ " Q1 3 1 $&! ": +1 0 $ Q1 3/ 0 0! +1 &" 5 & 0$1(! 7 &1 +1!$" ;<

20 5 Q1 3 7&( 0 $( &( & " 8C/7& &7" public void run(){ while (canrun){ sleep (3000); catch (InterruptedException ex) { counter+=3; if (counter >= Config.timeOut){ theserver.killconnection(); canrun=false; # ( 0$1( Q1 3 +1!+7!$&($ &&!+1" 5($ $("5( &$ & ($"' & 0$1(!,, & +$00 &$ $/ 70$ +$00 & & $Q1 37+&!+1" +1 5, 7&( 0!$ Q1 30!0$" ;! 8 5 7! # 0 7 "! ( 6+ & CM9P 8+ &! 07 0!11! *+" 8 / 1, (! + ( &+ 01&! " >

21 5! )&! & "A!$! &7/$++17! " ;!+!.3 5 %& 47 4 &" : *8,, 47 & 1! 0 " 5 *8,,!&"$"+ 1 (" outtoserver.flush(); mywatchdog.reset(); gzout=new GZIPOutputStream (outtoserver); int numbytes = infile.read(buffer, 0, Config.bufferSize); while (numbytes!= -1) { mywatchdog.reset(); gzout.write(buffer, 0, numbytes); numbytes = infile.read(buffer, 0, Config.bufferSize); gzout.close(); 5, #),2 &!$ +$00 ( 1 & &" 5%& $ 7 1 +, ($&, # ($&!$ "' *8,, + & 7&7! $ $ & 1! 69 0!1 $ & "51 +,) &!$" ;!(!8 5 0/ 7! & "! 4+1&! +" 5 8C!! &!$ 0/ & B& & " X +$( &" (+1! " 11 ;

22 "9 (07 1$(" 0/ &!$0/!" 5 & 0/*1 G ". & &" HDR 7! #:A ;2; P 0/ 4!! 69&"5 &7 (, +$ :7*K. :$ *K. [ #:A ''*=*> 6*''L 6'G*M P G/G** ==78 'G7>M : +$ & $ 69 " 5 ( ( &"# & 0/( 0 0! QK 1#:AP("5+&(%&1 &$' 1( 7 & (&" 5 : 7 0!7 $ &" 5 8MM +!! &" : R"R + 4 4&H2"2+1 ;R2"2+1 ">[/& "

23 <=9:68 9:68 28 /** Mini Web-Server *This is a mini web server for demonstration purposes. *It is written by Istvan Farkas with the very useful help of Gabor Paller. */ import java.io.*; import java.net.*; import java.util.*; import java.util.zip.gzipoutputstream; import java.text.*; class WatchDog extends Thread{ private ServerThread theserver; private int counter=0; private boolean canrun=true; WatchDog(ServerThread theserver){ this.theserver=theserver; this.setdaemon(true); public void reset(){ counter=0; public void disable (){ canrun=false; public void run(){ while (canrun){ sleep (3000); catch (InterruptedException ex) { counter+=3; if (counter >= Config.timeOut){ theserver.killconnection(); canrun=false; // run // class ServerThread extends Thread{ private Socket clientsocket; private Vector requests; // vector of all lines of request private Vector currentrequest; // elements of request line being parsed private String beforelaststringread,laststringread; // the last string read while reading the req private PrintStream outtoserver; private GZIPOutputStream gzout; private BufferedReader infromserver; private Date currentdate; //will get value when comm ing with client private StringTokenizer tokenizer=null; //used to tokenize the current

24 private WatchDog mywatchdog; request ServerThread (Socket clientsocket){ this.clientsocket=clientsocket; requests=new Vector(); currentrequest=new Vector(); mywatchdog=new WatchDog(this); mywatchdog.start(); public void serveget(){ String filename=null; // name of requested file File requestedfile=null; //the requested file as an object FileInputStream infile=null; boolean clientsupportsgzip=false; // Now serving a get. At the call of this function, currentrequest contains line 1 of the request. if (currentrequest.get(1).tostring().equals("/")) { filename = "index.html"; else { filename = currentrequest.get(1).tostring(); System.out.println("serveGet(): Requested filename: "+filename); //now detect whether client supports gzip for (int i=0; i<requests.size();i++){ if ((requests.get(i).tostring().touppercase().startswith("accept- ENCODING")) && (requests.get(i).tostring().touppercase().indexof("gzip")!=-1)) { clientsupportsgzip = true; if ((requests.get(i).tostring().touppercase().indexof ("GZIP;Q=0.")==-1) && (requests.get(i).tostring().touppercase(). indexof ("GZIP;Q=0")!=-1)){ clientsupportsgzip = false; // false if q=0 but not q=0.x requestedfile=new File(Config.basePath,fileName); infile=new FileInputStream(requestedFile); mywatchdog.reset(); outtoserver.print("http/ OK\r\n"); currentdate=new Date(); outtoserver.print("date: "+currentdate.togmtstring()+"\r\n"); outtoserver.print("server: Mini WebServer v."+config.version+"\r\n"); outtoserver.print("content-type: text/html\r\n"); if (Config.enableGZipEncoding && clientsupportsgzip) { outtoserver.print("content-encoding: gzip\r\n"); else { outtoserver.print("content-length: "+requestedfile.length()+"\r\n"); outtoserver.print("\r\n"); 2

25 if (Config.enableGZipEncoding && clientsupportsgzip){ //GZipped byte [] buffer = new byte[config.buffersize]; try{ outtoserver.flush(); mywatchdog.reset(); gzout=new GZIPOutputStream (outtoserver); int numbytes = infile.read(buffer, 0, Config.bufferSize); while (numbytes!= -1) { mywatchdog.reset(); gzout.write(buffer, 0, numbytes); numbytes = infile.read(buffer, 0, Config.bufferSize); gzout.close(); catch (IOException ioex){ System.out.println("DEBUG: Exception occured while GZiptransferring file."); ioex.printstacktrace(); else { //normal, uncompressed transfer byte [] buffer = new byte[config.buffersize]; try{ mywatchdog.reset(); int numbytes = infile.read(buffer, 0, Config.bufferSize); while (numbytes!= -1) { mywatchdog.reset(); outtoserver.write(buffer, 0, numbytes); numbytes = infile.read(buffer, 0, Config.bufferSize); catch (IOException ioex){ System.out.println("DEBUG: Exception occured while transferring file."); ioex.printstacktrace(); // end of else infile.close(); catch (Exception ex){ System.out.println("DEBUG: error occured while closing input file"); catch (FileNotFoundException ex){ // 404 String messagecontent="<html>\n<h1>404 - File Not Found</H1>\n"+ "Mini WebServer could not find the file you requested.<br>\n"+ "The filename you specified was: <strong>"+filename+ "</strong><br>\nplease try again.<br><br>mini WebServer v."+config.version+ " - written by Istvan Farkas in 2003\n"+ "<br>many heartfelt thanks to Gabor Paller. </HTML>"; mywatchdog.reset(); outtoserver.print("http/ File Not Found\r\n"); currentdate=new Date(); outtoserver.print("date: "+currentdate.togmtstring()+"\r\n"); outtoserver.print("server: Mini WebServer D

26 v."+config.version+"\r\n"); outtoserver.print("content-type: text/html\r\n"); outtoserver.print("content-length: "+messagecontent.length()+"\r\n\r\n"); outtoserver.print(messagecontent); return; public void tellbadrequest (){ // Called on unsupported HTTP command String messagecontent = "<HTML>\n<H1>400 - Bad Request</H1>\n" + "Sorry, but Mini WebServer does not support the HTTP command you requested.<br>\n" + "\nplease try again.<br><br>mini WebServer v."+config.version + " - written by Istvan Farkas in 2003\n" + "<br>many heartfelt thanks to Gabor Paller. </HTML>"; mywatchdog.reset(); outtoserver.print("http/ Bad Request\r\n"); currentdate = new Date(); outtoserver.print("date: " + currentdate.togmtstring()+"\r\n"); outtoserver.print("server: Mini WebServer v." + Config.version+"\r\n"); outtoserver.print("content-type: text/html\r\n"); outtoserver.print("content-length: " + messagecontent.length() + "\r\n\r\n"); outtoserver.print(messagecontent); return; catch (Exception ex) { System.out.println("DEBUG: Exception occured while writing to outtoserver"); public void killconnection(){ // to terminate connection System.out.println("ERROR: No active transfer for the determined timeout period - closing socket."); System.out.println("Closing connection on port "+clientsocket.getport()+" with address: "+clientsocket.getinetaddress()); ConnectionManager.removeConnection(); try{ clientsocket.close(); catch (Exception ex){ System.out.println("Debug: exception occured while closing the timed out transfer socket."); public void run(){ System.out.println("Activated connection on port "+clientsocket.getport()+" with address: "+clientsocket.getinetaddress()); outtoserver = new PrintStream( clientsocket.getoutputstream() ); infromserver = new BufferedReader( new InputStreamReader( clientsocket.getinputstream())); //now read all requests into a vector do { H

27 laststringread=infromserver.readline(); requests.add(laststringread); catch (IOException ex){ while ((laststringread.length()>0)); tokenizer=new StringTokenizer((String)requests.get(0)); while (tokenizer.hasmoretokens()) { currentrequest.add(tokenizer.nexttoken()); // Calls to serve different HTTP commands if (currentrequest.get(0).tostring().touppercase().startswith("get")) { serveget(); // else if... else { // Unsupported command tellbadrequest(); // The approriate function has finished serving request, now close connection. System.out.println("Closing connection on port "+clientsocket.getport()+" with address: "+clientsocket.getinetaddress()); ConnectionManager.removeConnection(); mywatchdog.disable(); clientsocket.close(); // The Thread will finish after this point. catch (IOException ex){ ex.printstacktrace(); // class Config{ //here we declare the config variables as static ones. We also give them default values. static final String version="0.2"; static String basepath="."; // the directory from which we are serving files static int buffersize=1024; static int maxconnections=64; static boolean enablegzipencoding=true; static int timeout=60; Config(){ //The constructor will read config from WebServer.ini BufferedReader inifile=null; inifile = new BufferedReader( new FileReader("WebServer.ini")); catch (FileNotFoundException ex){ System.out.println("Unable to read WebServer.ini, falling back to default configuration values..."); return; String templine=null; // the last line we read while parsing ini file do { =

28 templine=inifile.readline(); if (templine.touppercase().startswith("basepath")){ int index=templine.lastindexof("="); basepath=templine.substring(index+1); System.out.println("Config(): Set basepath to "+basepath); if (templine.touppercase().startswith("buffersize")){ int index=templine.lastindexof("="); buffersize=integer.parseint(templine.substring(index+1)); catch (Exception ex){ System.out.println("Config(): Set buffersize to "+buffersize+ " bytes"); if (templine.touppercase().startswith("maxconnections")){ int index=templine.lastindexof("="); buffersize=integer.parseint(templine.substring(index+1)); catch (Exception ex){ System.out.println("Config(): Set maxconnections to "+buffersize); if (templine.touppercase().startswith("enablegzipencoding")){ int index=templine.lastindexof("="); if (Integer.parseInt(tempLine.substring(index+1))==0) enablegzipencoding=false; catch (Exception ex){ System.out.println("Config(): Set enablegzipencoding to "+enablegzipencoding); if (templine.touppercase().startswith("timeout")){ int index=templine.lastindexof("="); timeout=integer.parseint(templine.substring(index+1)); catch (Exception ex){ if (timeout<10) timeout=10; System.out.println("Config(): Set timeout to "+timeout+" seconds."); catch (Exception ex){ while (templine!= null); // class ConnectionManager{ private static int nrofconnections=0; public static void addconnection(){ nrofconnections++; R

29 public static void removeconnection(){ if (nrofconnections!=0) { nrofconnections--; public static int getnrofconnections(){ return nrofconnections; // public class WebServer { int port=9000; // Where we are listening, default value is 9000 public void serve(string args[]){ System.out.println("\nSimple WebServer version "+Config.version+" \n"); port=integer.parseint(args[0]); catch (Exception ex){ System.out.println("Error parsing input port from args[0], falling back to default (9000)."); Config myconfig=new Config(); ServerSocket srvr = new ServerSocket(port); System.out.println( "Serving requests on port "+port+"..." ); Socket tempclientsocket; ServerThread tempthread; while( true ) { if (ConnectionManager.getNrOfConnections()<Config.maxConnections){ tempclientsocket = srvr.accept(); tempthread=new ServerThread (tempclientsocket); System.out.println("Accepting connection, this is nr. "+ConnectionManager.getNrOfConnections()); ConnectionManager.addConnection(); tempthread.start(); else { System.out.println("Error: too many connections, denying request."); catch( IOException ex ) { ex.printstacktrace(); System.out.println("Could not create server socket, maybe already in use."); return; public static void main(string args[]) { WebServer myserver=new WebServer(); myserver.serve(args); // <

30 " 2 F'8=<; +,--)))"0V"-01-01=<;" F'8=< +,--)))"0V"-01-01=<" F'8H;H +,--)))"0V"-01-01H;H" 5 )?" $,?(+/ ( * / 1/#;<<<. % 1K,0 1,#1+ +,--)))""-+! K$$ ),#)%&&Q +,--)))" "1-+$--!&->>->2--!&U)&" N$#": $,?1+ %&,$ +,--)))"!&)"1-!&)-!)/;/;<<H-!)/;/1"?$ %&$,8$M) +,--!&"$ "1-1--$- ) -1-1?&" >

Building a Multi-Threaded Web Server

Building a Multi-Threaded Web Server Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous

More information

Creating a Simple, Multithreaded Chat System with Java

Creating a Simple, Multithreaded Chat System with Java Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate

More information

Division of Informatics, University of Edinburgh

Division of Informatics, University of Edinburgh CS1Bh Lecture Note 20 Client/server computing A modern computing environment consists of not just one computer, but several. When designing such an arrangement of computers it might at first seem that

More information

Internet Technology. 02r. Programming with Sockets Paul Krzyzanowski. Rutgers University. Spring 2013

Internet Technology. 02r. Programming with Sockets Paul Krzyzanowski. Rutgers University. Spring 2013 Internet Technology 02r. Programming with Sockets Paul Krzyzanowski Rutgers University Spring 2013 February 7, 2013 2013 Paul Krzyzanowski 1 Sample Client-Server Program To illustrate programming with

More information

Application Development with TCP/IP. Brian S. Mitchell Drexel University

Application Development with TCP/IP. Brian S. Mitchell Drexel University Application Development with TCP/IP Brian S. Mitchell Drexel University Agenda TCP/IP Application Development Environment Client/Server Computing with TCP/IP Sockets Port Numbers The TCP/IP Application

More information

Outline. Introduction to Network Programming (java.net) Networking in Java Browsing (www) Custom networking (browsing)

Outline. Introduction to Network Programming (java.net) Networking in Java Browsing (www) Custom networking (browsing) Outline Introduction to Programming (java.net) Mazen.Malek.Shiaa@item.ntnu.no Applets All what you need about URLs Socket programming Implementation of client and server programs Datagrams Sources: 1.

More information

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket. 164 CHAPTER 2 APPLICATION LAYER connection requests, as done in TCPServer.java. If multiple clients access this application, they will all send their packets into this single door, serversocket. String

More information

Advanced Network Programming Lab using Java. Angelos Stavrou

Advanced Network Programming Lab using Java. Angelos Stavrou Advanced Network Programming Lab using Java Angelos Stavrou Table of Contents A simple Java Client...3 A simple Java Server...4 An advanced Java Client...5 An advanced Java Server...8 A Multi-threaded

More information

Programming Assignment: Development of a Proxy Cache

Programming Assignment: Development of a Proxy Cache Programming Assignment: Development of a Proxy Cache La prova avrà una valutazione da 0 a 3 punti da aggiungere alla media dell esito delle due prove di esonero scritte. La gestione dei thread non è da

More information

Mail User Agent Project

Mail User Agent Project Mail User Agent Project Tom Kelliher, CS 325 100 points, due May 4, 2011 Introduction (From Kurose & Ross, 4th ed.) In this project you will implement a mail user agent (MUA) that sends mail to other users.

More information

Assignment 4 Solutions

Assignment 4 Solutions CSCI 312 - DATA COMMUNICATIONS AND NETWORKS FALL, 2014 Assignment 4 Solutions Working as a pair Working in pairs. When you work as a pair you have to return only one home assignment per pair on a round.

More information

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab. Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command

More information

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime? CSCI 312 - DATA COMMUNICATIONS AND NETWORKS FALL, 2014 Assignment 4 Working as a group. Working in small gruops of 2-4 students. When you work as a group, you have to return only one home assignment per

More information

Threads - Chapter 13. Concurrent Programming Needs. The Implicit AWT Thread

Threads - Chapter 13. Concurrent Programming Needs. The Implicit AWT Thread Threads - Chapter 13 Threads allow a program to "do more than one thing at a time." If the hardware has multiple processing units, then this can result in faster execution of a program. In distributed

More information

Lesson: All About Sockets

Lesson: All About Sockets All About Sockets http://java.sun.com/docs/books/tutorial/networking/sockets/index.html Page 1 sur 1 The Java TM Tutorial Start of Tutorial > Start of Trail Trail: Custom Networking Lesson: All About Sockets

More information

Java Network. Slides prepared by : Farzana Rahman

Java Network. Slides prepared by : Farzana Rahman Java Network Programming 1 Important Java Packages java.net java.io java.rmi java.security java.lang TCP/IP networking I/O streams & utilities Remote Method Invocation Security policies Threading classes

More information

Java Support for developing TCP Network Based Programs

Java Support for developing TCP Network Based Programs Java Support for developing TCP Network Based Programs 1 How to Write a Network Based Program (In Java) As mentioned, we will use the TCP Transport Protocol. To communicate over TCP, a client program and

More information

Threads in der Client/Server-Programmierung mit Java

Threads in der Client/Server-Programmierung mit Java Threads in der Client/Server-Programmierung mit Java Zahlenraten: Protokoll CLIENT / Comm? Comm! / max / SERVER Comm? / Comm! / 100 trial / / cmp(trial) [ cmp(trial) = < or cmp(trial) = > ] [ answer =

More information

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

TP1 : Correction. Rappels : Stream, Thread et Socket TCP Université Paris 7 M1 II Protocoles réseaux TP1 : Correction Rappels : Stream, Thread et Socket TCP Tous les programmes seront écrits en Java. 1. (a) Ecrire une application qui lit des chaines au clavier

More information

Network Communication

Network Communication Network Communication Outline Sockets Datagrams TCP/IP Client-Server model OSI Model Sockets Endpoint for bidirectional communication between two machines. To connect with each other, each of the client

More information

Supplement: Text IO Using Reader and Writer. For Introduction to Java Programming By Y. Daniel Liang

Supplement: Text IO Using Reader and Writer. For Introduction to Java Programming By Y. Daniel Liang 0 Introduction Supplement: Text IO Using Reader and Writer For Introduction to Java Programming By Y. Daniel Liang The text introduced text I/O using the Scanner class and PrintWriter class, which greatly

More information

File Handling. Reading Character from File

File Handling. Reading Character from File File Handling The java.io package contains nearly every class you might ever need to perform input and output (I/O) in Java. All these streams represent an input source and an output destination. The stream

More information

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1 Introduction to Java Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233 ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1 What Is a Socket? A socket is one end-point of a two-way

More information

Network Programming using sockets

Network Programming using sockets Network Programming using sockets TCP/IP layers Layers Message Application Transport Internet Network interface Messages (UDP) or Streams (TCP) UDP or TCP packets IP datagrams Network-specific frames Underlying

More information

Java API Essentials (Part II) Web Languages Course 2009 University of Trento

Java API Essentials (Part II) Web Languages Course 2009 University of Trento Java API Essentials (Part II) Web Languages Course 2009 University of Trento Lab Objective More exercises on Object serialization Client-Server application through sockets Refresh basic Java concepts on

More information

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol). Java Network Programming The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol). The DatagramSocket class uses UDP (connectionless protocol). The java.net.socket

More information

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP CP4044 Lecture 7 1 Networking Learning Outcomes To understand basic network terminology To be able to communicate using Telnet To be aware of some common network services To be able to implement client

More information

MET 1313 COMMUNICATION AND COMPUTER NETWORKS. ASSIGNMENT 1 A Mail User Agent in Java

MET 1313 COMMUNICATION AND COMPUTER NETWORKS. ASSIGNMENT 1 A Mail User Agent in Java MET 1313 COMMUNICATION AND COMPUTER NETWORKS ASSIGNMENT 1 A Mail User Agent in Java In this assignment you will implement a mail user agent that sends mail to other users. Your task is to program the Simple

More information

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling

More information

Using Files as Input/Output in Java 5.0 Applications

Using Files as Input/Output in Java 5.0 Applications Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead

More information

1.00 Lecture 23. Streams

1.00 Lecture 23. Streams 1.00 Lecture 23 Input/Output Introduction to Streams Exceptions Reading for next time: Big Java 19.3-19.4 Streams Java can communicate with the outside world using streams Picture a pipe feeding data into

More information

Chapter Four: DFA Applications. Formal Language, chapter 4, slide 1

Chapter Four: DFA Applications. Formal Language, chapter 4, slide 1 Chapter Four: DFA Applications Formal Language, chapter 4, slide 1 1 We have seen how DFAs can be used to define formal languages. In addition to this formal use, DFAs have practical applications. DFAbased

More information

Data Communication & Networks G22.2262-001

Data Communication & Networks G22.2262-001 Data Communication & Networks G22.2262-001 Session 10 - Main Theme Java Sockets Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences 1 Agenda

More information

goal: learn how to build client/server applications that communicate using sockets socket: dropbox between application process and endend-transport

goal: learn how to build client/server applications that communicate using sockets socket: dropbox between application process and endend-transport Socket programming goal: learn how to build client/server applications that communicate using sockets socket: dropbox between application process and endend-transport protocol application process socket

More information

Computer Science Masters Project

Computer Science Masters Project Communication between Client and Server in the Distributed Object-oriented Repository Network Management System By Shan Jin Department of Computer Science Rensselaer Polytechnic Institute Troy, NY 12180-3590

More information

Java Programming Unit 10. Stock Price Quotes with URL, Sockets, and RMI

Java Programming Unit 10. Stock Price Quotes with URL, Sockets, and RMI Java Programming Unit 10 Stock Price Quotes with URL, Sockets, and RMI GeFng Stock Quotes From Yahoo! 1. Visit hjp://finance.yahoo.com, enter AAPL - the symbol of the Apple s stock, and press the bujon

More information

public static void main(string[] args) { System.out.println("hello, world"); } }

public static void main(string[] args) { System.out.println(hello, world); } } Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static

More information

Networking Code. Jeffrey Miller, Ph.D. CSCI 201L USC CSCI 201L

Networking Code. Jeffrey Miller, Ph.D. CSCI 201L  USC CSCI 201L Networking Code CSCI 201L Jeffrey Miller, Ph.D. HTTP://WWW-SCF.USC.EDU/~CSCI201 USC CSCI 201L Outline Server Networking Client Networking Program USC CSCI 201L 2/11 Server Software A server application

More information

Threads & Tasks: Executor Framework

Threads & Tasks: Executor Framework Threads & Tasks: Executor Framework Introduction & Motivation WebServer Executor Framework Callable and Future 12 April 2012 1 Threads & Tasks Motivations for using threads Actor-based Goal: Create an

More information

This material is built based on, Patterns covered in this class FILTERING PATTERNS. Filtering pattern

This material is built based on, Patterns covered in this class FILTERING PATTERNS. Filtering pattern 2/23/15 CS480 A2 Introduction to Big Data - Spring 2015 1 2/23/15 CS480 A2 Introduction to Big Data - Spring 2015 2 PART 0. INTRODUCTION TO BIG DATA PART 1. MAPREDUCE AND THE NEW SOFTWARE STACK 1. DISTRIBUTED

More information

JAVA - NETWORKING. Socket Programming: This is most widely used concept in Networking and it has been explained in very detail.

JAVA - NETWORKING. Socket Programming: This is most widely used concept in Networking and it has been explained in very detail. http://www.tutorialspoint.com/java/java_networking.htm JAVA - NETWORKING Copyright tutorialspoint.com The term network programming refers to writing programs that execute across multiple devices computers,

More information

Manual. Programmer's Guide for Java API

Manual. Programmer's Guide for Java API 2013-02-01 1 (15) Programmer's Guide for Java API Description This document describes how to develop Content Gateway services with Java API. TS1209243890 1.0 Company information TeliaSonera Finland Oyj

More information

Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

More information

The Vector class implements a resizable array of objects.

The Vector class implements a resizable array of objects. Library.mkr Page 730 Tuesday, December 7, 1999 1:31 PM Vector The Vector class implements a resizable array of objects. Vector( ) Constructs an empty vector. Vector( int initialcapacity ) Constructs an

More information

INPUT AND OUTPUT STREAMS

INPUT AND OUTPUT STREAMS INPUT AND OUTPUT The Java Platform supports different kinds of information sources and information sinks. A program may get data from an information source which may be a file on disk, a network connection,

More information

DNS: Domain Names. DNS: Domain Name System. DNS: Root name servers. DNS name servers

DNS: Domain Names. DNS: Domain Name System. DNS: Root name servers. DNS name servers DNS: Domain Name System DNS: Domain Names People: many identifiers: SSN, name, Passport # Internet hosts, routers: Always: IP address (32 bit) - used for addressing datagrams Often: name, e.g., nifc14.wsu.edu

More information

! "# $%&'( ) * ).) "%&' 1* ( %&' ! "%&'2 (! ""$ 1! ""3($

! # $%&'( ) * ).) %&' 1* ( %&' ! %&'2 (! $ 1! 3($ ! "# $%&'( ) * +,'-( ).) /"0'" 1 %&' 1* ( %&' "%&'! "%&'2 (! ""$ 1! ""3($ 2 ', '%&' 2 , 3, 4( 4 %&'( 2(! ""$ -5%&'* -2%&'(* ) * %&' 2! ""$ -*! " 4 , - %&' 3( #5! " 5, '56! "* * 4(%&'(! ""$ 3(#! " 42/7'89.:&!

More information

TCP Sockets. Multithreading. But first... Overview of Multithreading in Java. Background on Threads

TCP Sockets. Multithreading. But first... Overview of Multithreading in Java. Background on Threads But first... Background on Threads Overview of Multithreading in Java Multithreading Java has build-in support for concurrent programming. This enables you to have multiple flows of control, represented

More information

Network/Socket Programming in Java. Rajkumar Buyya

Network/Socket Programming in Java. Rajkumar Buyya Network/Socket Programming in Java Rajkumar Buyya Elements of C-S Computing a client, a server, and network Client Request Result Network Server Client machine Server machine java.net Used to manage: URL

More information

Socket-based Network Communication in J2SE and J2ME

Socket-based Network Communication in J2SE and J2ME Socket-based Network Communication in J2SE and J2ME 1 C/C++ BSD Sockets in POSIX POSIX functions allow to access network connection in the same way as regular files: There are special functions for opening

More information

Java I/O and Exceptions

Java I/O and Exceptions Java I/O and Exceptions CS1316: Representing Structure and Behavior Writing to a Text File We have to create a stream that allows us access to a file. We re going to want to write strings to it. We re

More information

Introduktion til distribuerede systemer uge 37 - fil og webserver

Introduktion til distribuerede systemer uge 37 - fil og webserver Introduktion til distribuerede systemer uge 37 - fil og webserver Rune Højsgaard 090678 1. delsstuderende 13. september 2005 1 Kort beskrivelse Implementationen af filserver og webserver virker, men håndterer

More information

Build your own Java library

Build your own Java library Build your own Java library Presented by developerworks, your source for great tutorials Table of Contents If you're viewing this document online, you can click any of the topics below to link directly

More information

Java URLs All material not from online sources/textbook copyright Travis Desell, 2012

Java URLs All material not from online sources/textbook copyright Travis Desell, 2012 Java URLs All material not from online sources/textbook copyright Travis Desell, 2012 Online References Working with URLs: http://docs.oracle.com/javase/tutorial/networking/ urls/index.html Overview What

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void

More information

Previously. Networking 2. Outline. TCP Client Side. Where s my server? Java Servers

Previously. Networking 2. Outline. TCP Client Side. Where s my server? Java Servers G52APR Java Application programming Networking 2 Michael Li http://www.cs.nott.ac.uk/~jwl/g52apr Previously Brief introduction to networking in Java What is IP and port How to find IP addresses (DNS lookup)

More information

Reading a Text File. Reading and Writing Text Files Exceptions. Testing for more input. Example: Count Words

Reading a Text File. Reading and Writing Text Files Exceptions. Testing for more input. Example: Count Words Reading a Text File Reading and Writing Text Files Exceptions 15-121 Fall 2010 Margaret Reid-Miller A Scanner object can be connected to many input sources: keyboard, file, network, string To read a text

More information

Input: an array of elements (e.g. integers) Output: an array containing all the elements provided as input in sorted order Steps

Input: an array of elements (e.g. integers) Output: an array containing all the elements provided as input in sorted order Steps Bubble Sort Input: an array of elements (e.g. integers) Output: an array containing all the elements provided as input in sorted order Steps take two adjacent elements at a time and compare them. if input[i]

More information

Socket Programming. Announcement. Lectures moved to

Socket Programming. Announcement. Lectures moved to Announcement Lectures moved to 150 GSPP, public policy building, right opposite Cory Hall on Hearst. Effective Jan 31 i.e. next Tuesday Socket Programming Nikhil Shetty GSI, EECS122 Spring 2006 1 Outline

More information

Socket programming. Socket Programming. Languages and Platforms. Sockets. Rohan Murty Hitesh Ballani. Last Modified: 2/8/2004 8:30:45 AM

Socket programming. Socket Programming. Languages and Platforms. Sockets. Rohan Murty Hitesh Ballani. Last Modified: 2/8/2004 8:30:45 AM Socket Programming Rohan Murty Hitesh Ballani Last Modified: 2/8/2004 8:30:45 AM Slides adapted from Prof. Matthews slides from 2003SP Socket programming Goal: learn how to build client/server application

More information

13 File Output and Input

13 File Output and Input SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to

More information

1. Programming Practice - Markov Chain Algorithm in Java

1. Programming Practice - Markov Chain Algorithm in Java 1. Programming Practice - Markov Chain Algorithm in Java Java classes of Markov chain algorithm Class Prefix Class Chain Class Markov Prefix Class class Prefix public Vector pref; // NPREF adjacent words

More information

ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty("java.security.policy","../server.java.

ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty(java.security.policy,../server.java. ExempleRMI.java import java.lang.*; import java.rmi.registry.*; import java.rmi.server.*; import java.io.*; import java.util.*; ExempleRMI.java import pkgexemple.*; public class ExempleRMI public static

More information

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets Transport layer protocols Interprocess communication Synchronous and asynchronous comm. Message destination Reliability Ordering Client Server Lecture 15: Operating Systems and Networks Behzad Bordbar

More information

Socket Programming in Java

Socket Programming in Java Socket Programming in Java Learning Objectives The InetAddress Class Using sockets TCP sockets Datagram Sockets Classes in java.net The core package java.net contains a number of classes that allow programmers

More information

JAVA I/O. Professeur Patrick BELLOT. TELECOM ParisTech

JAVA I/O. Professeur Patrick BELLOT. TELECOM ParisTech JAVA I/O Professeur Patrick BELLOT TELECOM ParisTech The notion of stream I/O in JAVA are based on the notion of stream. Input streams. Output streams. Streams allow to read from / write to: Disk files

More information

Table of Contents. LESSON: CASE Document Library...1

Table of Contents. LESSON: CASE Document Library...1 Table of Contents LESSON: CASE Document Library...1 Case Description...2 LABS...2 1. Creating the Document Class...2 2. Adding another constructor to Document class...2 3. Object Oriented Programming...2

More information

Topics. 1. Network & IP 2. TCP Sockets 3. UDP Sockets CDA FS13 2

Topics. 1. Network & IP 2. TCP Sockets 3. UDP Sockets CDA FS13 2 Java networking Carlo U. Nicola, IMVS With extracts from slides/publications of : Dominik Gruntz, IMVS and from the book of K.J. Calvert and M.J. Donahoo TCP in Java Topics 1. Network & IP 2. TCP Sockets

More information

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits) Binary I/O streams (ascii, 8 bits) InputStream OutputStream The Java I/O System The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing Binary I/O to Character I/O

More information

Files and input/output streams

Files and input/output streams Unit 9 Files and input/output streams Summary The concept of file Writing and reading text files Operations on files Input streams: keyboard, file, internet Output streams: file, video Generalized writing

More information

Applications Note: Connecting to Device Servers using Java

Applications Note: Connecting to Device Servers using Java Applications Note: Connecting to Device Servers using Java The following is a Java example which will help you understand what is involved in using Java to extract data dynamically from the NetPort/Cobox/Xport

More information

An Overview of Java. overview-1

An Overview of Java. overview-1 An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2

More information

gomobi Traffic Switching Guide Version 0.9, 28 September 2010

gomobi Traffic Switching Guide Version 0.9, 28 September 2010 gomobi Traffic Switching Guide Version 0.9, 28 September 2010 Mobile/Desktop Traffic Switching... 3 Summary of Options... 3 Single Site Solutions... 4 Server-side Switching Code... 4 JavaScript Switching

More information

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10) File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The

More information

public class demo1swing extends JFrame implements ActionListener{

public class demo1swing extends JFrame implements ActionListener{ import java.io.*; import java.net.*; import java.io.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class demo1swing extends JFrame implements ActionListener JButton demodulacion;

More information

A constructor : Constructor

A constructor : Constructor Java Constructors Constructor A constructor : is used in the creation of an object. is a special method with no return type. must have the same name as the class it is in. is used to initialize the object.

More information

B.Sc (Honours) - Software Development

B.Sc (Honours) - Software Development Galway-Mayo Institute of Technology B.Sc (Honours) - Software Development E-Commerce Development Technologies II Lab Session Using the Java URLConnection Class The purpose of this lab session is to: (i)

More information

CS 121 Intro to Programming:Java - Lecture 11 Announcements

CS 121 Intro to Programming:Java - Lecture 11 Announcements CS 121 Intro to Programming:Java - Lecture 11 Announcements Next Owl assignment up, due Friday (it s short!) Programming assignment due next Monday morning Preregistration advice: More computing? Take

More information

Input / Output Framework java.io Framework

Input / Output Framework java.io Framework Date Chapter 11/6/2006 Chapter 10, start Chapter 11 11/13/2006 Chapter 11, start Chapter 12 11/20/2006 Chapter 12 11/27/2006 Chapter 13 12/4/2006 Final Exam 12/11/2006 Project Due Input / Output Framework

More information

Apéndice C: Código Fuente del Programa DBConnection.java

Apéndice C: Código Fuente del Programa DBConnection.java Apéndice C: Código Fuente del Programa DBConnection.java import java.sql.*; import java.io.*; import java.*; import java.util.*; import java.net.*; public class DBConnection Connection pgsqlconn = null;

More information

EVALUATION OF TOOLS FOR CYBER SECURITY

EVALUATION OF TOOLS FOR CYBER SECURITY Project report 2: EVALUATION OF TOOLS FOR CYBER SECURITY By Piyali Basak Indian Institute of Technology, Kanpur Guided by Dr. N.P. Dhavale Deputy General Manager, Strategic Business Unit, Institute for

More information

Cmp Sci 187: Introduction to Software Design. Following Chapter 1 of text (Koffmann and Wolfgang)

Cmp Sci 187: Introduction to Software Design. Following Chapter 1 of text (Koffmann and Wolfgang) Cmp Sci 187: Introduction to Software Design Following Chapter 1 of text (Koffmann and Wolfgang) Outline The software challenge and the software life cycle Activities of each phase of the software life

More information

Introduction to Java Sockets and. CIT Concurrency RMI

Introduction to Java Sockets and. CIT Concurrency RMI Introduction to Java Sockets and RMI Basic Concepts TCP versus UDP over IP Transmission Control Protocol, User Datagram Protocol, Internet Protocol Reliable versus unreliable packet delivery Reliable =

More information

Word Count Code using MR2 Classes and API

Word Count Code using MR2 Classes and API EDUREKA Word Count Code using MR2 Classes and API A Guide to Understand the Execution of Word Count edureka! A guide to understand the execution and flow of word count WRITE YOU FIRST MRV2 PROGRAM AND

More information

The University of Melbourne Department of Computer Science and Software Engineering Software Design Second Semester, 2003 Tutorial 11 Week 12

The University of Melbourne Department of Computer Science and Software Engineering Software Design Second Semester, 2003 Tutorial 11 Week 12 The University of Melbourne Department of Computer Science and Software Engineering 433-254 Software Design Second Semester, 2003 Tutorial 11 Week 12 1. What are design patterns? Develop and discuss a

More information

Using Data Compression to Improve Application Server Performance

Using Data Compression to Improve Application Server Performance Using Data Compression to Improve Application Server Performance Peter Haggar Senior Software Engineer Emerging Technology IBM Corporation Research Triangle Park, NC haggar@us.ibm.com Peter Haggar Using

More information

EPITA Première Année Cycle Ingénieur. Atelier Java - J4

EPITA Première Année Cycle Ingénieur. Atelier Java - J4 EPITA Première Année Cycle Ingénieur marwan.burelle@lse.epita.fr http://www.lse.epita.fr Overview 1 Subclass of Thread Implementing Runnable 2 3 Using Sockets Using URL Subclass of Thread Implementing

More information

What is an I/O Stream?

What is an I/O Stream? Java I/O Stream 1 Topics What is an I/O stream? Types of Streams Stream class hierarchy Control flow of an I/O operation using Streams Byte streams Character streams Buffered streams Standard I/O streams

More information

CISC 4700 L01 Network & Client- Server Programming Spring 2016. Harold, Chapter 8: Sockets for Clients

CISC 4700 L01 Network & Client- Server Programming Spring 2016. Harold, Chapter 8: Sockets for Clients CISC 4700 L01 Network & Client- Server Programming Spring 2016 Harold, Chapter 8: Sockets for Clients Datagram: Internet data packet Header: accounting info (e.g., address, port of source and dest) Payload:

More information

When the transport layer tries to establish a connection with the server, it is blocked by the firewall. When this happens, the RMI transport layer

When the transport layer tries to establish a connection with the server, it is blocked by the firewall. When this happens, the RMI transport layer Firewall Issues Firewalls are inevitably encountered by any networked enterprise application that has to operate beyond the sheltering confines of an Intranet Typically, firewalls block all network traffic,

More information

WRITING DATA TO A BINARY FILE

WRITING DATA TO A BINARY FILE WRITING DATA TO A BINARY FILE TEXT FILES VS. BINARY FILES Up to now, we have looked at how to write and read characters to and from a text file. Text files are files that contain sequences of characters.

More information

COSC 6397 Big Data Analytics. Distributed File Systems (II) Edgar Gabriel Spring 2014. HDFS Basics

COSC 6397 Big Data Analytics. Distributed File Systems (II) Edgar Gabriel Spring 2014. HDFS Basics COSC 6397 Big Data Analytics Distributed File Systems (II) Edgar Gabriel Spring 2014 HDFS Basics An open-source implementation of Google File System Assume that node failure rate is high Assumes a small

More information

become familiar with the concept of an I/O stream understand the difference between binary files and text files learn how to save data in a file

become familiar with the concept of an I/O stream understand the difference between binary files and text files learn how to save data in a file Chapter 9 become familiar with the concept of an I/O stream understand the difference between binary files and text files learn how to save data in a file learn how to read data from a file Overview of

More information

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

Hadoop WordCount Explained! IT332 Distributed Systems

Hadoop WordCount Explained! IT332 Distributed Systems Hadoop WordCount Explained! IT332 Distributed Systems Typical problem solved by MapReduce Read a lot of data Map: extract something you care about from each record Shuffle and Sort Reduce: aggregate, summarize,

More information

Using DOTS as Apache Derby System Test

Using DOTS as Apache Derby System Test Using DOTS as Apache Derby System Test Date: 02/16/2005 Author: Ramandeep Kaur ramank@yngvi.org Table of Contents 1 Introduction... 3 2 DOTS Overview... 3 3 Running DOTS... 4 4 Issues/Tips/Hints... 6 5

More information

Rationale for Software Architecture

Rationale for Software Architecture Rationale for Software Architecture Bedir Tekinerdoğan University of Twente Department of Computer Science Enschede, The Netherlands e:mail bedir@cs.utwente.nl http://www.cs.utwente.nl/~bedir/ http://trese.cs.utwente.nl/taosad/

More information

A Simple Client-Server Application

A Simple Client-Server Application A Simple Client-Server Application The Java language has several classes that are used for network programming. They are in the java.net package and are adaptations of the corresponding structures in C.

More information

F28DA11 Command Line Java Survival. Phil Trinder and David H. Marwick

F28DA11 Command Line Java Survival. Phil Trinder and David H. Marwick F28DA11 Command Line Java Survival Guide Phil Trinder and David H. Marwick Java with BlueJ BlueJ is a Java development environment explicitly for teaching introductory objectoriented programming Java has

More information

COSC 6397 Big Data Analytics. Mahout and 3 rd homework assignment. Edgar Gabriel Spring 2014. Mahout

COSC 6397 Big Data Analytics. Mahout and 3 rd homework assignment. Edgar Gabriel Spring 2014. Mahout COSC 6397 Big Data Analytics Mahout and 3 rd homework assignment Edgar Gabriel Spring 2014 Mahout Scalable machine learning library Built with MapReduce and Hadoop in mind Written in Java Focusing on three

More information