📄 dxclient.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: DxClient.java,v 1.3 2003/03/12 12:30:23 per_nyfelt Exp $package org.ozoneDB.DxLib.net;import java.io.*;import java.net.*;import org.ozoneDB.DxLib.*;import org.ozoneDB.io.stream.ResolvingObjectInputStream;/** * DxClient stellt ein Ende einer Socketverbindung dar, an die DxCompatibles * gesendet oder empfangen werden koennen. am anderen Ende der Verbindung * sollte entweder ein DxServer oder DxMultiServer sein. * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.3 $Date: 2003/03/12 12:30:23 $ */public class DxClient extends DxObject { /** * The size of the stream buffers. When all data fits into this buffer * performance increases. TODO: change this into a configurable setting, so * db users can change to their needs. */ protected final static int buffSize = 8192; protected Socket sock; protected ObjectInputStream in; protected ObjectOutputStream out; public DxClient() { } public DxClient( String host, int port ) throws IOException { sock = new Socket( host, port ); init(); onConnect(); } public DxClient( Socket s ) throws IOException { sock = s; init(); onConnect(); } protected void init() throws IOException { // this buffer size values seems to work for a localhost connections // which is the fastest possible case; we rely on OS setting however // since the kernel may better know what is a good buffer size; with // many connections this may lead to memory issues // sock.setSendBufferSize( buffSize * 10 ); // sock.setReceiveBufferSize( buffSize * 10 ); // System.out.println( sock.getSendBufferSize() + ", " + sock.getReceiveBufferSize() ); out = new ObjectOutputStream( new BufferedOutputStream( sock.getOutputStream(), buffSize ) ); // send the header data out.flush(); in = new ResolvingObjectInputStream( new BufferedInputStream( sock.getInputStream(), buffSize ) ); } /** * Diese Methode wird ausgefuehrt, wenn Verbindung zum Server aufgenommen * wird. Sie kann ueberschrieben werden, um ein Verbindungsprotokoll zu * implementieren. */ public void onConnect() throws IOException { } /** * Diese Methode wird analog zu onConnect() beim schliessen der Verbindung * aufgenommen. */ public void onDeconnect() throws IOException { } public void send( Object obj ) throws IOException { try { out.writeObject( obj ); } finally { out.flush(); out.reset(); } } public Object receive() throws IOException, ClassNotFoundException { return in.readObject(); } /** * prueft ob daten im input stream liegen */ public boolean objectAvailable() { try { return in.available() > 0; } catch (IOException e) { return false; } } public synchronized void close() throws IOException { onDeconnect(); // in.close(); in = null; // out.flush(); // out.close(); out = null; sock.close(); sock = null; } public ObjectInputStream inputStream() { return in; } public ObjectOutputStream outputStream() { return out; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -