Code example for Socket

Methods: getInputStream, getOutputStream, isClosed, setSoTimeout

0
            // jndi.40=Unable to connect: bad IP address 
            throw new DomainProtocolException(Messages.getString("jndi.40")); //$NON-NLS-1$ 
        } 
        try { 
            srvAddr = InetAddress.getByAddress(srvAddrArr);
            socket = new Socket(srvAddr, serverPort);
            socket.setSoTimeout(timeout);
            oStream = new BufferedOutputStream(socket.getOutputStream());
            ProviderMgr.write16Int(outBufLen, tmpArr, 0);
            oStream.write(tmpArr, 0, 2);
            oStream.write(outBuf, 0, outBufLen);
            oStream.flush();
            iStream = socket.getInputStream();
            iStream.read(tmpArr, 0, 2);
            inLen = ProviderMgr.parse16Int(tmpArr, 0);
            if (inLen > inBufLen) {
                // jndi.43=Output buffer is too small 
                throw new DomainProtocolException(Messages.getString("jndi.43")); //$NON-NLS-1$ 
            } 
            actualLen = iStream.read(inBuf, 0, inLen);
            if (actualLen != inLen) {
                // jndi.44=Error while receiving message over TCP 
                throw new DomainProtocolException(Messages.getString("jndi.44")); //$NON-NLS-1$ 
            } 
        } catch (IllegalStateException e) {
            // jndi.41=Error while querying DNS server 
            throw new DomainProtocolException(Messages.getString("jndi.41"), e); //$NON-NLS-1$
        } catch (SocketTimeoutException e) {
            throw (e);
        } catch (IOException e) {
            // jndi.41=Error while querying DNS server 
            throw new DomainProtocolException(Messages.getString("jndi.41"), e); //$NON-NLS-1$
        } finally { 
            if (socket != null && !socket.isClosed()) {
                try { 
                    socket.close();
                } catch (IOException e) {
                } 
            }