{"id":21871939,"url":"https://github.com/avinandanbose/javanetworking","last_synced_at":"2026-01-11T13:19:57.683Z","repository":{"id":64620770,"uuid":"576237528","full_name":"AvinandanBose/JavaNetworking","owner":"AvinandanBose","description":"This is all about Network  Collection of Java . NET ","archived":false,"fork":false,"pushed_at":"2022-12-30T19:06:19.000Z","size":158,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-05T12:25:57.822Z","etag":null,"topics":["java","network","networking"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AvinandanBose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-09T10:38:53.000Z","updated_at":"2024-01-12T18:52:42.000Z","dependencies_parsed_at":"2023-01-31T14:00:56.547Z","dependency_job_id":null,"html_url":"https://github.com/AvinandanBose/JavaNetworking","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AvinandanBose%2FJavaNetworking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AvinandanBose%2FJavaNetworking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AvinandanBose%2FJavaNetworking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AvinandanBose%2FJavaNetworking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AvinandanBose","download_url":"https://codeload.github.com/AvinandanBose/JavaNetworking/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246307932,"owners_count":20756478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","network","networking"],"created_at":"2024-11-28T06:15:51.924Z","updated_at":"2026-01-11T13:19:57.648Z","avatar_url":"https://github.com/AvinandanBose.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaNetworking\nThis is all about Java Networking.\n\n\u003ch1\u003eJavaNetworking \u003c/h1\u003e\n\u003ch3\u003e The systems connected over a network through the internet connect to each other with the help of Transmission Control Protocol(TCP) or User Datagram Protocol(UDP). In Java, programming is done on the application layer that uses the concept of the classes in the java.net package , which provide networking functions to users. \u003c/h3\u003e \n\n\n\n\u003ch1 align=\"center\"\u003e InetAddress[Internet Addressing] \u003c/h1\u003e\n\n\u003cul\u003e\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BgetByName%5D.java\"\u003eGetByName\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nDetermines the IP address of a host, given the host's name.\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BgetAllByName%5D.java\"\u003eGetAllByName\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nGiven the name of a host, returns an array of its IP addresses, \nbased on the configured name service on the system.\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BgetAddress%5D.java\"\u003eGetAddress\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nReturns the raw IP address of  InetAddress object. \nAs it returns byte value hence we have to do AND\nOperation with 0xff(Hex)= 255 (1111 1111), to get actual value.\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BgetHostName%5D.java\"\u003eGetHostName\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nGets the host name for the IP address.\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BgetHostAddress%5D.java\"\u003eGetHostAddress\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nReturns the IP address string in textual presentation.\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BgetCanonicalHostName%5D.java\"\u003eCanonicalHostName\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nGets the fully qualified domain name for the IP address.\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BgetLocalHost%5D.java\"\u003eGetLocalHost\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nReturns the address of the local host. \nThis is achieved by retrieving the name of the host from the system,\nthen resolving that name into an InetAddress.\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BgetLoopbackAddress%5D.java\"\u003eGetLoopbackAddress\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nReturns the loopback address.\n\nThe InetAddress returned will represent the IPv4 loopback address, 127.0.0.1, \nor the IPv6 loopback address, ::1. \n\nNote: The IP address 127.0. 0.1 is called a loopback address.\nPackets sent to this address never reach the network ,\nbut are looped through the network interface card only. \nThis can be used for diagnostic purposes to verify,\nthat the internal path through the TCP/IP protocols is working.\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BhashCode%5D.java\"\u003eHashCode\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nReturns a hashcode for this IP address.\n```\n\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisAnyLocalAddress%5D.java\"\u003eisAnyLocalAddress\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\nUtility routine to check if the InetAddress is a wildcard address.\nWild Card Address is a special local IP address.\ni.e. \nFor Net Mask : 255.255.255.255 → Wild Card Mask : 0.0.0.0\nFor Net Mask : 255.255.255.254 → Wild Card Mask : 0.0.0.1\nFor Net Mask : 255.255.255.252 → Wild Card Mask : 0.0.0.3\nFor Net Mask : 255.255.255.248 → Wild Card Mask : 0.0.0.7\n.....\n\nFor Net Mask : 0.0.0.0 → Wild Card Mask : 255.255.255.255\n\nNote :\n\nFormula = \nStarting Value is Always : 255.255.255.255\n(Substract)\nSubnet Mask =  Wild Card Mask\n\ni.e.\n\n255.255.255.255 - Subnet Mask = Wild Card Mask\n\nA wildcard mask is a mask of bits that indicates ,\nwhich parts of an IP address are available for examination.\n\nA wildcard mask can be thought of as an inverted subnet mask.\ni.e.\n(Subnet Mask)255.255.255.0  → 0.0.0.255(Wild Card Mask)\n\nA wild card mask is a matching rule in which:\n\n0 means that the equivalent bit must match(Care)and \n1 means that the equivalent bit does not matter(Don't Care).\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisLinkLocalAddress%5D.java\"\u003eisLinkLocalAddress\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nUtility routine to check if the InetAddress is an link local address.\n\nLinkink Local Address: A link-local address is an automated selected,\nIPv6 unicast( one-to-one transmission ) network address ,\nthat is valid only for communications within the subnetwork that the host is connected to.\nA link-local address is required on each physical interface.\n\nLink-local addresses are designed to be used for addressing on a single link,\nfor purposes such as automatic address configuration, neighbor discovery, \nor in the absence of routers.\n\nIt also may be used to communicate with other nodes on the same link. \nA link-local address is automatically assigned.\n\nA link-local address is the IP address that is to be used for communication ,\nwithin a logical division of the network or in the broadcast domain ,\nto which the host is connected.\n\nRange of Link Local Ip Address : 169.254.x.x\nwhere x ranges from : 0 - 255 \n\ni.e. The Range is between : 169.254.0.0 -\n169.254.255.255\n\nEach computer randomly select an IP address in a given Range.\nAnd then communicate to other Computer searching for the same ,\nIP address through ARP(Address Resolution Protocol (ARP)), \nif not found then the automated selected IP belongs to the \nComputer.\n\nNote: A link-local address is an IPv6 unicast address ,\nthat can be automatically configured on any interface .\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisLoopbackAddress%5D.java\"\u003eisLinkLocalAddress\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nUtility routine to check if the InetAddress is a loopback address.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisMCGlobal%5D.java\"\u003eisMCGlobal\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nUtility routine to check if the multicast address has global scope.\n\n \nMulticast: In a Multicast Transmission,\n  All stations recieves the frame, the stations that\n  are members of the group keeps and handles the frame.\n  The protocol that is used  \n  Internet Group Management Protocol . \n  It uses Class D of IP address , where \n  1110 - these 4 bits are fixed in Octet\n  and other 28 bits can be used in maximum\n  of 2^28 bits . Therefore 1st Octet will\n  range from : 1110 0000 - 1110 1111\n  that is 224-239. And least significant \n  bit of the of the first byte in a destination\n  address is always 1 in Multicasting,\n  where as in Unicast it is 0.\n  \n```\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisMCLinkLocal%5D.java\"\u003eisMCLinkLocal\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nUtility routine to check if the multicast address has link scope.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisMCNodeLocal%5D.java\"\u003eisMCNodeLocal\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nUtility routine to check if the multicast address has node scope.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisMCOrgLocal%5D.java\"\u003eisMCOrgLocal\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nUtility routine to check if the multicast address has organization scope.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisMCSiteLocal%5D.java\"\u003eisMCSiteLocal\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nUtility routine to check if the multicast address has site scope.\n\n```\n\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisMulticastAddress%5D.java\"\u003eisMulticastAddress\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nUtility routine to check if the InetAddress is an IP multicast address.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisReachable%5D.java\"\u003eisReachable\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nTest whether that address is reachable. \n\nBest effort is made by the implementation to try to reach the host, \nbut firewalls and server configuration may block requests resulting,\nin a unreachable status while some specific ports may be accessible.\nA typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained,\notherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host.\n\nThe timeout value, in milliseconds, indicates the maximum amount of time the try should take. \nIf the operation times out before getting an answer, the host is deemed unreachable. \nA negative value will result in an IllegalArgumentException being thrown.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BisSiteLocalAddress%5D.java\"\u003eisSiteLocalAddress\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nUtility routine to check if the InetAddress is a site local address.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddress%5BtoString%5D.java\"\u003etoString\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nConverts this IP address to a String. The string returned is of the form: hostname / literal IP address.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/javaInetAddressTest%5BhashCode%5D.java\"\u003ehashCode\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nReturns a hashcode for the given IP address.\n\n```\n\n\u003c/ul\u003e\n\n\n\n\u003ch3\u003e Q 1) Lets Look at a program which prompts the user for a hostname and then it looks up the IP address for the hostname and displays the result. Once done , it asks the user if he or she wants to look up another host: \u003c/h3\u003e\n\n\u003cul\u003e\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/Answer1.java\"\u003eAnswer-1\u003c/h3\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch3\u003e Q 2)Printing address of  Host of Local Device(local host ) and Host of an website.  \u003c/h3\u003e\n\n\u003cul\u003e\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/Answer2.java\"\u003eAnswer-2\u003c/h3\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch1 align=\"center\"\u003e Socket Class \u003c/h1\u003e\n\n\u003cul\u003e\n\n\u003ch2 align=\"center\"\u003e 1. Constructors of Socket Class \u003c/h2\u003e\n\n\n\u003cul\u003e\n\u003ch2\u003e Socket() constructor {Creating UnConnected Socket}\u003c/h2\u003e\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/Socket%5BCreation%20of%20Socket%5D.java\"\u003eCreation of Unconnected Socket-1\u003c/h3\u003e\u003c/li\u003e\n \n ```Syntax\n \n import java.net.Socket → Socket Package\n \n Socket s = new Socket(); → Creating an instance of Socket\n ```\n \n \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/SocketNew.java\"\u003eCreation of Unconnected Socket -2\u003c/h3\u003e\u003c/li\u003e\n \n \n ```Syntax\n \n import java.net.Socket → Socket Package\n\nnew Socket(); → Anonymously Creating an instance of Socket\n ```\n \n \u003ch2\u003eUsing Inet in Constructor \u003c/h2\u003e \n \n \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/Socket%5BConnecting%20Address%20Through%20a%20Port%5D-Constructor1.java\"\u003eConnecting InetAddress Through a Port-Constructor1\u003c/h3\u003e\u003c/li\u003e\n \n ```Syntax\n \n import java.net.Socket → Socket Package\n import java.net.InetAddress;\n \n InetAddress address = InetAddress.getByName(host);\n Socket s = new Socket(address.getHostAddress(), int port); \n  \n  Or\n  \n  Socket s = new Socket(address.getHostName(), int port);  \n ```\n \n  \n \n  \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/Socket%5BConnecting%20Address%20Through%20a%20Port%5D-Constructor2.java\"\u003eConnecting InetAddress Through a Port-Constructor2\u003c/h3\u003e\u003c/li\u003e\n \n ```Syntax\n \nimport java.net.Socket → Socket Package\nimport java.net.InetAddress;\n\nstatic Socket s;\nInetAddress address = InetAddress.getByName(host);\nInetAddress localAdress = InetAddress.getLocalHost();\ns = new Socket(address.getHostAddress(), int port, localAdress, localPort);\n   \nOr\n   \ns = new Socket(address.getHostName(), int port, localAdress, localPort);   \n   \n ```\n \n  \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/SocketNew2.java\"\u003eConnecting InetAddress Through a Port-Constructor3\u003c/h3\u003e\u003c/li\u003e\n \n ```Syntax\n \nimport java.net.Socket → Socket Package\nimport java.net.InetAddress;\n\nstatic Socket s;\nInetAddress address = InetAddress.getByName(host);\nInetAddress localAdress = InetAddress.getLocalHost();\ns = new Socket(address.getHostAddress(), int port, boolean);\n   \nOr\n   \ns = new Socket(address.getHostName(), int port, localAdress, boolean);   \n   \n ```\n \n \u003ch2\u003eUsing String in Constructor \u003c/h2\u003e \n \n \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/SocketNew3.java\"\u003eConnecting String Address Through a Port-Constructor4\u003c/h3\u003e\u003c/li\u003e\n \n```Syntax\n \nimport java.net.Socket → Socket Package\n\n\nstatic Socket s;\n\nString address = hostname;\nsocket = new Socket(address, 80);\n\n// socket = new Socket(hostname, int port);\n   \n ```\n \n \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/SocketNew4.java\"\u003eConnecting String Address Through a Port-Constructor5\u003c/h3\u003e\u003c/li\u003e\n \n```Syntax\n \nimport java.net.Socket → Socket Package\nimport java.net.InetAddress;\n\nstatic Socket s;\n\n String address = hostname;\n InetAddress localAdress = InetAddress.getLocalHost();\nsocket = new Socket(address, int port, localAdress, int localPort); \n\n// socket = new Socket( hostname, int port,localAdress, int localPort);\n   \n ```\n \n \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/SocketNew5.java\"\u003eConnecting String Address Through a Port-Constructor6\u003c/h3\u003e\u003c/li\u003e\n \n```Syntax\n \nimport java.net.Socket → Socket Package\n\n\nstatic Socket s;\n\n String address = hostname;\n \nsocket = new Socket(address, int port, boolean); \n\n// socket = new Socket( hostname, int port, boolean);\n   \n ```\n \n \n \u003ch2\u003eUsing Proxy in Constructor \u003c/h2\u003e \n   \n \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/Socket%5BConnecting%20Address%20Through%20a%20Port%5D-Constructor5.java\"\u003eConnecting Socket Through a Proxy and Input String Address -Constructor7\u003c/h3\u003e\u003c/li\u003e\n  \n  \n \n  ```Syntax\nimport java.net.InetSocketAddress;\nimport java.net.Proxy;\nimport java.net.Socket;\nimport java.net.SocketAddress;\n\nSocketAddress address = new InetSocketAddress(hostname, int port);\nProxy proxy = new Proxy(Proxy.Type.HTTP, address);\nSocket s = new Socket(proxy);\n\nProxy socksProxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(hostname, int port));\nSocket s1 = new Socket(socksProxy);\n\n ```\n \n  \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/SocketNew6.java\"\u003eConnecting Socket Through a Proxy and Input Inet Address -Constructor8\u003c/h3\u003e\u003c/li\u003e\n  \n ```Syntax\nimport java.net.InetSocketAddress;\nimport java.net.Proxy;\nimport java.net.Socket;\nimport java.net.SocketAddress;\nimport java.net.InetAddress;\n\nInetAddress address = InetAddress.getByName(hostname);\nSocketAddress address = new InetSocketAddress(address, int port);\nProxy proxy = new Proxy(Proxy.Type.HTTP, address);\nSocket s = new Socket(proxy);\n\nProxy socksProxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(hostname,  intport));\nSocket s1 = new Socket(socksProxy);\n\n ```  \n \u003ch2 align=\"Center\"\u003e In Details \u003c/h2\u003e\n \n\u003ctable\u003e\n \u003ctr\u003e\n \u003cth \u003eConstructors\u003c/th\u003e\n \u003cth \u003eDoes this\u003c/th\u003e\n\u003c/tr\u003e \n\u003ctr\u003e\n  \u003ctd  \u003eSocket()\u003c/td\u003e\n  \u003ctd  \u003eIt creates an unconnected socket with the system-default of SocketImpl\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd  \u003eSocket(InetAddress address, int port)\u003c/td\u003e\n  \u003ctd  \u003eIt is creates a stream socket and connects it to the specified port number at the specified IP address. \u003c/td\u003e\n  \n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd  \u003eSocket(InetAddress address, int port, boolean stream)\u003c/td\u003e\n  \u003ctd  \u003eIt is depreciated and it uses DatagramSocket instead of UDP transport. \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd  \u003eSocket(InetAddress address, int port, InetAddress localAddr, int localport) \u003c/td\u003e\n  \u003ctd  \u003eIt creates a socket and connects it to the specified remote address of specified remote port. \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd  \u003eSocket(Proxy proxy) \u003c/td\u003e\n  \u003ctd  \u003eIt creates an unconnected socket, specifying the type of proxy that should be used regardless of any other settings. \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd  \u003eSocket(String address, int port)\u003c/td\u003e\n  \u003ctd  \u003eIt is creates a stream socket and connects it to the specified port number on the named host. \u003c/td\u003e\n  \n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd  \u003eSocket(String address, int port, boolean stream)\u003c/td\u003e\n  \u003ctd  \u003eIt is depreciated and it uses DatagramSocket instead of UDP transport. \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n  \u003ctd  \u003eSocket(InetAddress address, int port, InetAddress localAddr, int localport) \u003c/td\u003e\n  \u003ctd  \u003eIt creates a socket and connects it to the specified remote host of specified remote port. \u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\u003ch2\u003e Other types of Inet And Socket connections: \u003c/h2\u003e\n\n \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/Socket%5BConnecting%20Address%20Through%20a%20Port%5D-Constructor3.java\"\u003eConnecting InetAddress Through a Port-Other Types-1\u003c/h3\u003e\u003c/li\u003e\n \n ```Syntax\n \n import java.net.Socket → Socket Package\n import java.net.InetAddress;\n  \n  InetAddress address = InetAddress.getByName(host); \n Socket s = new Socket(); \n s.connect( new java.net.InetSocketAddress(address.getHostAddress(), int port));\n  \n  Or\n  \n  s.connect( new java.net.InetSocketAddress(address.getHostName(), int port));\n ```\n \n  \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/Socket%5BConnecting%20Address%20Through%20a%20Port%5D-Constructor4.java\"\u003eConnecting InetAddress Through a Port-Other Types-2\u003c/h3\u003e\u003c/li\u003e\n   \n  \n \n ```Syntax\n \nimport java.net.InetSocketAddress;\nimport java.net.Socket;\nimport java.net.SocketAddress;\nimport java.net.InetAddress;\n \n static Socket socket = new Socket();\n InetAddress address = InetAddress.getByName(host);\nSocketAddress addr = new InetSocketAddress(address.getHostAddress(), int port);\n   \nOr\n   \nSocketAddress addr = new InetSocketAddress(address.getHostName(), int port);\n   \nAnd then:\n   \n socket.connect(addr);\n \n```\n\u003ch3\u003e \u003ci\u003e \u003cins\u003eNote \u003c/ins\u003e \u003c/i\u003e: Same thing can be attained by String .\u003c/h3\u003e\n\u003c/ul\u003e\n \u003ch2 align=\"center\"\u003e 2. Methods of Socket Class \u003c/h2\u003e\n\u003cul\u003e\n  \u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/SocketMethods1.java\"\u003eVoid Bind(SocketAddress bindpoint)\u003c/h3\u003e\u003c/li\u003e\n  \n```Syntax\n\n  It binds socket to a local address and port number.\n  \n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods2.java\"\u003eVoid Close()\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\n  It closes the socket.\n  \n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods3.java\"\u003eVoid Connect(Socket endpoint)\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\n  It connects this socket to the server.\n  \n```\n\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods4.java\"\u003eVoid Connect(Socket endpoint, int timeout)\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\n  It connects this socket to the server  with a specified timeout value.\n  \n```\n\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods5.java\"\u003eSocketChannel getChannel\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nIt returns the unique SocketChannel object associated with the socket if any.\n\n:Note:\n\nThe Java NIO SocketChannel is used for connecting a channel with a TCP \n(Transmission Control Protocol) network socket. \nIt is equivalent to Java Networking Sockets used in network programming.\n\nIt is provided by: java.nio package .\n\nNIO represents New Input/Output , where as,\nIO represents Input/Output of java.io package. \n\nJava.NIO package have Channels provided by\n\njava.nio.channels interface and one of the Channels is:\n\nSocketChannel which is a Class.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods6.java\"\u003eInetAddress getInetAddress\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nIt returns the address to which the socket is connected.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods7.java\"\u003eInputStream getInputStream\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nIt returns an input stream for this socket.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods8.java\"\u003eSetKeepAlive and GetKeepAlive\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nSetKeepAlive: If Set to True, then SO_KEEPALIVE is enabled\n\nGetKeepALive: If SetKeepAlive is true , then GetKeepAlive returns True else false.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods9.java\"\u003eInetAddress getLocalAddress\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nIt gets the local address to which the socket is bound.\n\n```\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods10.java\"\u003eint getLocalPort()\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nIt returns the local port to which the current socket is bound .\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods11.java\"\u003eSocketAddress getLocalSocketAddress\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nIt returns the address of the endpoint to which the socket is bound,\nor null if it is not bound yet.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods12.java\"\u003eOutputStream getOutputStream\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nIt returns the outputstream for the connected socket.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods13.java\"\u003eboolean getOOBInline\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nThe setOOBInline() method of Java Socket class enables \nor disables the SO_OOBInline. By default, the SO_OOBInline option is disabled.\n\n```\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods14.java\"\u003eint getPort()\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nIt returns the remote port to which the socket is connected to.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods15.java\"\u003eint getRecieveBufferSize()\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nIt gets the value of the SO_RCVBUF option for this socket, that is,\nthe buffer size used by the platform for the input on this Socket.\n\n```\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods16.java\"\u003eSocketAddress getRemoteSocketAddress()\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nReturns the address of the endpoint this socket is connected to, \nor null if it is unconnected.\n\nIf the socket was connected prior to being closed, \nthen this method will continue to return the connected address,\nafter the socket is closed.\n\n```\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods17.java\"\u003eboolean getReuseAddress()\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nTests if SO_REUSEADDR is enabled.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods18.java\"\u003eint getSendBufferSize\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nGet value of the SO_SNDBUF option for this Socket, \nthat is the buffer size used by the platform for output on this Socket.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods19.java\"\u003eint getSoLinger()\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nReturns setting for SO_LINGER. -1 returns implies that the option is disabled. \nThe setting only affects socket close.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods20.java\"\u003eint getSoTimeout()\u003c/h3\u003e\u003c/li\u003e\n\n\n```Syntax\n\nReturns setting for SO_TIMEOUT. 0 returns implies that the option is disabled \n(i.e., timeout of infinity).\n\n```\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods21.java\"\u003eboolean getTcpNoDelay()\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nTests if TCP_NODELAY is enabled.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods22.java\"\u003eint getTrafficClass()\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nGets traffic class or type-of-service in the IP header for packets sent from this Socket\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods23.java\"\u003eboolean isBound()\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nReturns the binding state of the socket.\nReturns true if the socket was successfuly bound to an address.\n```\n\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods24.java\"\u003eboolean isClosed()\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nReturns the closed state of the socket.\nReturns true if the socket has been closed.\n\n```\n\n\u003cli\u003e\u003ch3\u003e \u003ca href=\"https://github.com/AvinandanBose/JavaNetworking/blob/main/socketmethods25.java\"\u003eboolean isConnected()\u003c/h3\u003e\u003c/li\u003e\n\n```Syntax\n\nReturns the connection state of the socket.\n\nNote:  Closing a socket doesn't clear its connection state, \nwhich means this method will return true for a closed socket (see isClosed()) \nif it was successfuly connected prior to being closed.\n\n```\n\n\n\u003c/ul\u003e\n\u003c/ul\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favinandanbose%2Fjavanetworking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favinandanbose%2Fjavanetworking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favinandanbose%2Fjavanetworking/lists"}