Code example for Socket

Methods: getInputStreamgetLocalAddressgetLocalPortgetOutputStream

0
	public Echo(String host, int port, String peerHost, int peerPort)
			throws IOException, UnknownHostException { 
		this.peerIp = InetAddress.getByName(peerHost);
		//this.port = port; 
 
		ss = new Socket(host, port, peerIp, peerPort);
		out = ss.getOutputStream();
		in = ss.getInputStream();
		System.out.println("Connected...");
		System.out.println("TO: " + host + ":" + port);
		System.out.println("LocalAddress: "
				+ ss.getLocalAddress().getHostAddress() + ":"
				+ ss.getLocalPort());
 
	} 
 
	public Echo(String host, int port) throws IOException, UnknownHostException {
 
		System.out.println("Connecting...");
		ss = new Socket(host, port);
Stop searching for code, let great code find you!  Add Codota to your java IDE