tailieunhanh - Bài giảng Công nghệ Java: Chương 14 - Trần Quang Diệu
Chương 14 giúp người học hiểu về "Java socket programming". Nội dung trình bày cụ thể gồm có: Java Sockets Programming, Socket Methods, InputStream Basics, ServerSocket Class (TCP Passive Socket), ServerSocket Methods, Socket programming with TCP, DatagramSocket Constructors,. | 5/14/2020 6:23:21 AM CÔNG NGHỆ JAVA CH14. JAVA SOCKET PROGRAMMING Quang Dieu Tran PhD. Java Sockets Programming The package provides support for sockets programming (and more). Typically you import everything defined in this package with: import .*; 5/14/2020 6:23:21 AM Classes InetAddress Socket ServerSocket DatagramSocket DatagramPacket 5/14/2020 6:23:21 AM InetAddress class static methods you can use to create new InetAddress objects. getByName(String host) getAllByName(String host) getLocalHost() InetAddress x = ( “”); Throws UnknownHostException 5/14/2020 6:23:21 AM Sample Code: Uses InetAddress class to lookup hostnames found on command line. > java Lookup 5/14/2020 6:23:21 AM try { InetAddress a = (hostname); (hostname + ":" + ()); } catch (UnknownHostException e) { ("No address found for " + hostname); } 5/14/2020 6:23:21 AM Socket class Corresponds to active TCP sockets only! client sockets socket returned by accept(); Passive sockets are supported by a different class: ServerSocket UDP sockets are supported by DatagramSocket 5/14/2020 6:23:21 AM JAVA TCP Sockets Implements client sockets (also called just “sockets”). An endpoint for communication between two machines. Constructor and Methods Socket(String host, int port): Creates a stream socket and connects it to the specified port number on the named host. InputStream getInputStream() OutputStream getOutputStream() close() Implements server sockets. Waits for requests to come in over the network. Performs some operation based on the request. Constructor and Methods ServerSocket(int port) Socket Accept(): Listens for a connection to be made to this socket and accepts it. This method blocks until a connection is made. . | 5/14/2020 6:40:49 AM CÔNG NGHỆ JAVA CH14. JAVA SOCKET PROGRAMMING Quang Dieu Tran PhD. Java Sockets Programming The package provides support for sockets programming (and more). Typically you import everything defined in this package with: import .*; 5/14/2020 6:40:49 AM Classes InetAddress Socket ServerSocket DatagramSocket DatagramPacket 5/14/2020 6:40:49 AM InetAddress class static methods you can use to create new InetAddress objects. getByName(String host) getAllByName(String host) getLocalHost() InetAddress x = ( “”); Throws UnknownHostException 5/14/2020 6:40:49 AM Sample Code: Uses InetAddress class to lookup hostnames found on command line. > java Lookup 5/14/2020 6:40:49 AM try { InetAddress a = (hostname); (hostname + ":" + ()); } catch (UnknownHostException
đang nạp các trang xem trước