1 // NAME
2 // $RCSfile: ContextSocketFace.java,v $
3 // DESCRIPTION
4 // [given below in javadoc format]
5 // DELTA
6 // $Revision: 1.12 $
7 // CREATED
8 // $Date: 2006/02/09 14:30:19 $
9 // COPYRIGHT
10 // Westhawk Ltd
11 // TO DO
12 //
13
14 /*
15 * Copyright (C) 2000 - 2006 by Westhawk Ltd
16 * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
17 *
18 * Permission to use, copy, modify, and distribute this software
19 * for any purpose and without fee is hereby granted, provided
20 * that the above copyright notices appear in all copies and that
21 * both the copyright notice and this permission notice appear in
22 * supporting documentation.
23 * This software is provided "as is" without express or implied
24 * warranty.
25 * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
26 */
27
28 package uk.co.westhawk.snmp.net;
29
30 /*-
31 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32 * SNMP Java Client
33 * ჻჻჻჻჻჻
34 * Copyright 2023 MetricsHub, Westhawk
35 * ჻჻჻჻჻჻
36 * This program is free software: you can redistribute it and/or modify
37 * it under the terms of the GNU Lesser General Public License as
38 * published by the Free Software Foundation, either version 3 of the
39 * License, or (at your option) any later version.
40 *
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Lesser Public License for more details.
45 *
46 * You should have received a copy of the GNU General Lesser Public
47 * License along with this program. If not, see
48 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
49 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50 */
51
52 import java.io.*;
53
54 /**
55 * The interface for the different type of sockets.
56 *
57 * @author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
58 * @version $Revision: 1.12 $ $Date: 2006/02/09 14:30:19 $
59 */
60 public interface ContextSocketFace {
61 static final String version_id = "@(#)$Id: ContextSocketFace.java,v 1.12 2006/02/09 14:30:19 birgit Exp $ Copyright Westhawk Ltd";
62
63 /**
64 * Creates the socket. This socket is used when listening for incoming
65 * requests or traps.
66 * Use only one (1) of the two create methods.
67 *
68 * @param port The local port number were we receive (listen for)
69 * packets
70 * @param bindAddr The local address the server will bind to when
71 * listening
72 *
73 * @see #create(String, int, String)
74 */
75 public void create(int port, String bindAddr) throws IOException;
76
77 /**
78 * Creates the socket. This socket is used to send out our requests. Use
79 * only one (1) of the two create methods.
80 *
81 * @param host The name of the host that is to receive our packets
82 * @param port The port number of the host
83 * @param bindAddr The local address the server will bind to when
84 * sending packets
85 *
86 * @see #create(int, String)
87 */
88 public void create(String host, int port, String bindAddr) throws IOException;
89
90 /**
91 * Returns the IP address of the host we sent the packet to.
92 * Only applicable when sending requests, not when (only) listening for
93 * incoming requests or traps.
94 *
95 * @return The IP address, or null when the hostname cannot be determined
96 * @see #getReceivedFromHostAddress
97 */
98 public String getSendToHostAddress();
99
100 /**
101 * Returns the IP address of the (latest) host of the packet we received.
102 * Only applicable when anything has been received.
103 * When sending a request, this will in most cases be the same host
104 * where we sent the original packet to.
105 *
106 * @return The IP address, or null when the hostname cannot be determined
107 * @see #getSendToHostAddress
108 */
109 public String getReceivedFromHostAddress();
110
111 /**
112 * Returns the address of the endpoint this socket is bound to, or null
113 * if it is not bound yet.
114 *
115 * @since 4_14
116 */
117 public String getLocalSocketAddress();
118
119 /**
120 * Returns the address of the endpoint this socket is connected to, or
121 * null if it is unconnected.
122 *
123 * @since 4_14
124 */
125 public String getRemoteSocketAddress();
126
127 /**
128 * Receives a packet from this socket. The StreamPortItem object
129 * contains the host and port the packet came from.
130 *
131 * @param maxRecvSize the maximum number of bytes to receive
132 * @return the packet
133 */
134 public StreamPortItem receive(int maxRecvSize) throws IOException;
135
136 /**
137 * Sends a packet from this socket.
138 * It can throw an "java.io.IOException: Invalid argument" when the
139 * bind address is incorrect for some reason.
140 *
141 * @param packet the packet
142 */
143 public void send(byte[] packet) throws IOException;
144
145 /**
146 * Closes this socket.
147 */
148 public void close();
149
150 }