| 1 |
< |
import java.net.*; |
| 1 |
> |
//---PACKAGE DECLARATION--- |
| 2 |
|
|
| 3 |
+ |
//---IMPORTS--- |
| 4 |
|
|
| 5 |
+ |
import java.net.*; |
| 6 |
+ |
import java.io.*; |
| 7 |
+ |
|
| 8 |
|
/** |
| 9 |
< |
* LowLevelNet - Basic Netowking Class for Java Host <br><br> |
| 10 |
< |
* Version 1.0 <br><br> |
| 11 |
< |
* Version History: <br> |
| 12 |
< |
* 16/11/00 1.0 Initial Version <br> |
| 13 |
< |
* <br> |
| 14 |
< |
* @author Ash Beeson <a href="mailto:ab11@ukc.ac.uk">ab11@ukc.ac.uk</a> |
| 11 |
< |
*/ |
| 9 |
> |
* Provides low level network functions for JavaHost |
| 10 |
> |
* <DETAILED DESCRIPTION> |
| 11 |
> |
* |
| 12 |
> |
* @author $Author$ |
| 13 |
> |
* @version $Id$ |
| 14 |
> |
*/ |
| 15 |
|
class LowLevelNet { |
| 16 |
|
|
| 17 |
< |
/** |
| 15 |
< |
* sendUDPPacket - will attempt to send a UDP packet containing 'inText' to server |
| 16 |
< |
* on the specificed port. |
| 17 |
< |
*/ |
| 18 |
< |
public static void sendUDPPacket( Config config, String inText ){ |
| 19 |
< |
|
| 20 |
< |
if ( inText.length() != 0 ){ |
| 21 |
< |
|
| 22 |
< |
// will throw an exception if an error occurs, so must bung it in a try |
| 23 |
< |
// try { |
| 24 |
< |
DatagramPacket udp = new DatagramPacket( inText.getBytes(), inText.length(), config.getFilterName(), config.getFilterUDPPort() ); |
| 25 |
< |
// } |
| 26 |
< |
//catch ( UnknownHostException e ){ |
| 27 |
< |
// the serverName supplied could not be resolved using dns |
| 28 |
< |
// } |
| 29 |
< |
} |
| 30 |
< |
} |
| 17 |
> |
//---FINAL ATTRIBUTES--- |
| 18 |
|
|
| 19 |
< |
|
| 19 |
> |
//---STATIC METHODS--- |
| 20 |
> |
|
| 21 |
> |
/** |
| 22 |
> |
* sendUDPPacket - will attempt to send a UDP packet containing 'inText' to server |
| 23 |
> |
* on the specificed port. |
| 24 |
> |
*/ |
| 25 |
> |
public static void sendUDPPacket( Config config, String inText ){ |
| 26 |
> |
|
| 27 |
> |
if ( inText.length() != 0 ){ |
| 28 |
> |
//System.out.println("SENT: "+inText); |
| 29 |
> |
// will throw an exception if an error occurs, so must bung it in a try |
| 30 |
> |
try { |
| 31 |
> |
DatagramPacket udp = new DatagramPacket( inText.getBytes(), inText.length(), config.getFilterName(), config.getFilterUDPPort() ); |
| 32 |
> |
DatagramSocket sendSoc = new DatagramSocket(); |
| 33 |
> |
sendSoc.send(udp); |
| 34 |
> |
} |
| 35 |
> |
catch ( SocketException e ){ |
| 36 |
> |
// the serverName supplied could not be resolved using dns |
| 37 |
> |
} |
| 38 |
> |
catch ( IOException e ){ |
| 39 |
> |
// problem sending.. |
| 40 |
> |
} |
| 41 |
> |
} |
| 42 |
> |
} |
| 43 |
> |
|
| 44 |
> |
//---CONSTRUCTORS--- |
| 45 |
> |
|
| 46 |
> |
//---PUBLIC METHODS--- |
| 47 |
> |
|
| 48 |
> |
//---PRIVATE METHODS--- |
| 49 |
> |
|
| 50 |
> |
//---ACCESSOR/MUTATOR METHODS--- |
| 51 |
> |
|
| 52 |
> |
//---ATTRIBUTES--- |
| 53 |
> |
|
| 54 |
> |
//---STATIC ATTRIBUTES--- |
| 55 |
|
|
| 56 |
< |
} |
| 56 |
> |
} |