Lab#3 Sockets (i) Book reading: Kurose 2.7

Other info: •

http://download.oracle.com/javase/6/docs/api/index.html



The Sockets API ◦ What is a Socket? What identifies a socket? ◦ Types of sockets



Sockets in Java ◦ TCP Sockets ▪ Socket class. Use of close. ▪ TCP Clients •

Exception handling with try … catch



Readin from a socket: getInputStream. Line oriented reading with Scanner class. Methods: next, nextInt, nextLine, hasNext …. ◦ Reading from the keyboard.



Writing to a socket: getOuputStream. Text-oriented write : PrintWriter class. ◦ print & println. Warning: platform-depented end-of-line. ▪ Warning: The need of flushing buffers to avoid a deadlock. método flush (flush method on clases OutputStream & PrintWriter).

◦ InetAddress class for Internet Addresses in Java. ▪ How to learn about addresses in use in the current connection: métodos getLocalPort, getPort, getLocalAddress and getInetAddress. ▪ Getting parameters from standard input. Convert an String into an int for port numbers.

Exercises: •

Exercise#1: Write a program that will connect to port 80 at server “www.upv.es”, printing the message “Connected!” after establishing the connection and next closing the connection and ending. (No need to include exception handling code).



Exercise#2: Add another method to the program above. This new method will do as #1 but now exception handling is required (using try … catch). Change the connected message to string “Connected again!”. •

Run it and check it works too.



Now change port number to 81 and try again. What happens?



Restore port number to 80. Change the server name adding an additional “w” to the name. Try again to see what happens.



When trying to connect a socket, when do UnknownHostException and IOException happen?



Exercise#3: Add a new method to your program that will connect to port 25 on “smtp.upv.es” server, after the connection is made, it will read the first text line from the socket and it will print it to the standard output.



Exercise#4: Daytime client. It just connects to port 13 on “ntp.upv.es” server and it prints a single line to stdout.



Exercise#5: Basic HTTP/1.0 client. It will connect to port 80 on “www.upv.es” server and it will transmit the text “GET / HTTP/1.0\r\n\r\n”. Next it will wait for any received text over the socket that will be printed to stdout.



Excercise#6: Add yet another method to your program. This time it will be a client connecting to port 25 on UPV STMP server (smtp.upv.es). Once the connection is established, the program will show the values of local and remote port and the IP address of the server. Run it three times and notice the changes in the values shown.



Exercise#7(optional): Make changes to the program above so it will accept server name and port number as command line arguments.

Sockets (i) Book reading: Other info

Sockets (i). Book reading: Kurose 2.7. Other info: • http://download.oracle.com/javase/6/docs/api/index.html. • The Sockets API. ◦ What is a Socket? What identifies a socket? ◦ Types of sockets. • Sockets in Java. ◦ TCP Sockets. ▫ Socket class. Use of close. ▫ TCP Clients. • Exception handling with try … catch. • Readin from a ...

52KB Sizes 0 Downloads 86 Views

Recommend Documents

UDP Sockets
TCP guarantees the delivery of packets and preserves their order on destination. Sometimes these features are not required, since they do not come without performance costs, it would be better to use a lighter transport protocol such as UDP (User Dat

sharing-info-other-programs-1617 (1).pdf
[email protected]. Return this form to: Riverview School, PO Box 69, Silver Lake, WI 53170 by 9/1/2016. In accordance with Federal civil rights ...

I. Basic Info Student Committee Members: • Emily ...
ABET is the engineering accreditation system. It accredits ChE, EE, ... biology background are generally necessary for the BM track, yet ABET does not allow any Bi classes to count toward accreditation. Therefore, despite that Bi/Ch110 is a requireme

Unit I Reading--Slave Rebellions.pdf
raid the arsenal, kill all the white residents, free the. slaves, and burn the city to the ground. Like Gabriel Prosser, Vesey was betrayed by. some of his followers.

Sumer Camp Turo 2015 Info i reserva.pdf
Loading… Page 1. Whoops! There was a problem loading more pages. Retrying... Sumer Camp Turo 2015 Info i reserva.pdf. Sumer Camp Turo 2015 Info i reserva.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Sumer Camp Turo 2015 Info i rese

Sumer Camp Turo 2015 Info i reserva.pdf
Games, Chess, Creative Robotics, Computers, etc. , a banda de les més esportives, com el futbol. en camp de gespa, el pàdel, les passejades amb mountain ...

Parent Portal Info Access Info and Mobile App for Schools.pdf ...
Retrying... Whoops! There was a problem previewing this document. Retrying. ... Parent Portal Info Access Info and Mobile App for Schools.pdf. Parent Portal Info ...

Info-Marche_final.pdf
des droits de chacun·e dans nos communautés. Les personnes trans et allié·e·s de tous âges et tous. genres sont les bienvenu·e·s. Cet événement sera filmé et photographié par des. membres de la communauté et des médias. Soyez. prêt·eÂ

Info Forms.pdf
Marching Band Shoes: Size ______ $30 ______. Total: ______. Please make checks out to Wauconda HS. All marching band shoes, lyres, and flip. folders purchased with this order will be given to the students on the first day of. marching band camp Augus

Provisional info
Sign in. Loading… Page 1. Whoops! There was a problem loading more pages. Retrying... Provisional info. Provisional info. Open. Extract. Open with. Sign In.

INFO PACK.pdf
In all participating countries, xenophobia and discrimination form a big problem. Especially. economic crisis contributes to this situation, when foreigners are ...

Info. Practices_Delhi.pdf
NOTE : Full 2 marks to be allotted if reason explained with the help of. any correct example. (b) Compare BUS topology with STAR topology. Give example. 2. Ans. BUS topology STAR topology. In Bus topology all the nodes are. joined to one cable (the b

info-primaria.pdf
Loading… Whoops! There was a problem loading more pages. Whoops! There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Main menu. There was a problem previewing

Practical info -
Mar 19, 2018 - Baltic Sea Labour Forum (7 min). • Baltic Science Network (7 min) b. Emerging flagship;. • BSR SMART LIFE (7 min). 4. Thematic discussions in five groups. Participants can choose two groups (90 min (45 min in each group)). • Comb