Java Doc for SocketConnection.java in  » 6.0-JDK-Modules » j2me » javax » microedition » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » javax.microedition.io 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.microedition.io.SocketConnection

All known Subclasses:   com.sun.cdc.io.j2me.socket.Protocol,
SocketConnection
public interface SocketConnection extends StreamConnection(Code)
This interface defines the socket stream connection.

A socket is accessed using a generic connection string with an explicit host and port number. The host may be specified as a fully qualified host name or IPv4 number. e.g. socket://host.com:79 defines a target socket on the host.com system at port 79.

Note that RFC1900 recommends the use of names rather than IP numbers for best results in the event of IP number reassignment.

Closing Streams

Every StreamConnection provides a Connection object as well as an InputStream and OutputStream to handle the I/O associated with the connection. Each of these interfaces has its own close() method. For systems that support duplex communication over the socket connection, closing of the input or output stream SHOULD shutdown just that side of the connection. e.g. closing the InputStream will permit the OutputStream to continue sending data.

Once the input or output stream has been closed, it can only be reopened with a call to Connector.open(). The application will receive an IOException if an attempt is made to reopen the stream.

BNF Format for Connector.open() string

The URI must conform to the BNF syntax specified below. If the URI does not conform to this syntax, an IllegalArgumentException is thrown.

<socket_connection_string> ::= "socket://"<hostport>
<hostport> ::= host ":" port
<host> ::= host name or IP address (omitted for inbound connections, See ServerSocketConnection)
<port> ::= numeric port number

Examples

The following examples show how a SocketConnection would be used to access a sample loopback program.

 SocketConnection sc = (SocketConnection)
 Connector.open("socket://host.com:79");
 sc.setSocketOption(SocketConnection.LINGER, 5);
 InputStream is  = sc.openInputStream();
 OutputStream os = sc.openOutputStream();
 os.write("\r\n".getBytes());
 int ch = 0;
 while(ch != -1) {
 ch = is.read();
 }
 is.close();
 os.close();
 sc.close();
 


Field Summary
final public  byteDELAY
     Socket option for the small buffer writing delay (0).
final public  byteKEEPALIVE
     Socket option for the keep alive feature (2).
final public  byteLINGER
     Socket option for the linger time to wait in seconds before closing a connection with pending data output (1).
final public  byteRCVBUF
     Socket option for the size of the receiving buffer (3).
final public  byteSNDBUF
     Socket option for the size of the sending buffer (4).


Method Summary
public  StringgetAddress()
     Gets the remote address to which the socket is bound.
public  StringgetLocalAddress()
     Gets the local address to which the socket is bound.
public  intgetLocalPort()
     Returns the local port to which this socket is bound.
public  intgetPort()
     Returns the remote port to which this socket is bound.
public  intgetSocketOption(byte option)
     Get a socket option for the connection.
public  voidsetSocketOption(byte option, int value)
     Set a socket option for the connection.

Options inform the low level networking code about intended usage patterns that the application will use in dealing with the socket connection.

Calling setSocketOption to assign buffer sizes is a hint to the platform of the sizes to set the underlying network I/O buffers. Calling getSocketOption can be used to see what sizes the system is using. The system MAY adjust the buffer sizes to account for better throughput available from Maximum Transmission Unit (MTU) and Maximum Segment Size (MSS) data available from current network information.


Parameters:
  option - socket option identifier (KEEPALIVE, LINGER,SNDBUF, RCVBUF, or DELAY)
Parameters:
  value - numeric value for specified option
exception:
  IllegalArgumentException - if the value is notvalid (e.g.

Field Detail
DELAY
final public byte DELAY(Code)
Socket option for the small buffer writing delay (0). Set to zero to disable Nagle algorithm for small buffer operations. Set to a non-zero value to enable.



KEEPALIVE
final public byte KEEPALIVE(Code)
Socket option for the keep alive feature (2). Setting KEEPALIVE to zero will disable the feature. Setting KEEPALIVE to a non-zero value will enable the feature.



LINGER
final public byte LINGER(Code)
Socket option for the linger time to wait in seconds before closing a connection with pending data output (1). Setting the linger time to zero disables the linger wait interval.



RCVBUF
final public byte RCVBUF(Code)
Socket option for the size of the receiving buffer (3).



SNDBUF
final public byte SNDBUF(Code)
Socket option for the size of the sending buffer (4).





Method Detail
getAddress
public String getAddress() throws IOException(Code)
Gets the remote address to which the socket is bound. The address can be either the remote host name or the IP address(if available). the remote address to which the socket is bound.
exception:
  IOException - if the connection was closed.



getLocalAddress
public String getLocalAddress() throws IOException(Code)
Gets the local address to which the socket is bound.

The host address(IP number) that can be used to connect to this end of the socket connection from an external system. Since IP addresses may be dynamically assigned, a remote application will need to be robust in the face of IP number reassignment.

The local hostname (if available) can be accessed from System.getProperty("microedition.hostname")

the local address to which the socket is bound.
exception:
  IOException - if the connection was closed.
See Also:   ServerSocketConnection



getLocalPort
public int getLocalPort() throws IOException(Code)
Returns the local port to which this socket is bound. the local port number to which this socket is connected.
exception:
  IOException - if the connection was closed.
See Also:   ServerSocketConnection



getPort
public int getPort() throws IOException(Code)
Returns the remote port to which this socket is bound. the remote port number to which this socket is connected.
exception:
  IOException - if the connection was closed.



getSocketOption
public int getSocketOption(byte option) throws IllegalArgumentException, IOException(Code)
Get a socket option for the connection.
Parameters:
  option - socket option identifier (KEEPALIVE, LINGER,SNDBUF, RCVBUF, or DELAY) numeric value for specified option or -1 if thevalue is not available.
exception:
  IllegalArgumentException - if the option identifier isnot valid
exception:
  IOException - if the connection was closed
See Also:   SocketConnection.setSocketOption



setSocketOption
public void setSocketOption(byte option, int value) throws IllegalArgumentException, IOException(Code)
Set a socket option for the connection.

Options inform the low level networking code about intended usage patterns that the application will use in dealing with the socket connection.

Calling setSocketOption to assign buffer sizes is a hint to the platform of the sizes to set the underlying network I/O buffers. Calling getSocketOption can be used to see what sizes the system is using. The system MAY adjust the buffer sizes to account for better throughput available from Maximum Transmission Unit (MTU) and Maximum Segment Size (MSS) data available from current network information.


Parameters:
  option - socket option identifier (KEEPALIVE, LINGER,SNDBUF, RCVBUF, or DELAY)
Parameters:
  value - numeric value for specified option
exception:
  IllegalArgumentException - if the value is notvalid (e.g. negative value) or if the optionidentifier is not valid
exception:
  IOException - if the connection was closed
See Also:   SocketConnection.getSocketOption



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.