Socket Socket Class

Definition

Provides a client-side TCP socket.

[Android.Runtime.Register("java/net/Socket", ApiSince=1, DoNotGenerateAcw=true)]
public class Socket : Java.Lang.Object, IDisposable, Java.IO.ICloseable
type Socket = class
    inherit Object
    interface ICloseable
    interface IJavaObject
    interface IDisposable
Inheritance
Derived
Attributes
Implements

Remarks

Android platform documentation

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Socket() Socket()

Creates a new unconnected socket.

Socket(InetAddress, Int32) Socket(InetAddress, Int32)

Creates a new streaming socket connected to the target host specified by the parameters dstAddress and dstPort.

Socket(InetAddress, Int32, Boolean) Socket(InetAddress, Int32, Boolean)

Creates a new streaming or datagram socket connected to the target host specified by the parameters addr and port.

Socket(InetAddress, Int32, InetAddress, Int32) Socket(InetAddress, Int32, InetAddress, Int32)

Creates a new streaming socket connected to the target host specified by the parameters dstAddress and dstPort.

Socket(IntPtr, JniHandleOwnership) Socket(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Socket(Proxy) Socket(Proxy)

Creates a new unconnected socket using the given proxy type.

Socket(SocketImpl) Socket(SocketImpl)

Creates an unconnected socket with the given socket implementation.

Socket(String, Int32) Socket(String, Int32)

Creates a new streaming socket connected to the target host specified by the parameters dstName and dstPort.

Socket(String, Int32, Boolean) Socket(String, Int32, Boolean)

Creates a new streaming or datagram socket connected to the target host specified by the parameters hostName and port.

Socket(String, Int32, InetAddress, Int32) Socket(String, Int32, InetAddress, Int32)

Creates a new streaming socket connected to the target host specified by the parameters dstName and dstPort.

Properties

Channel Channel

Returns this socket's SocketChannel, if one exists.

Class Class

Returns the unique instance of Class that represents this object's class.

(Inherited from Object)
Handle Handle

The handle to the underlying Android instance.

(Inherited from Object)
IJavaObjectEx.IsProxy IJavaObjectEx.IsProxy Inherited from Object
IJavaObjectEx.KeyHandle IJavaObjectEx.KeyHandle Inherited from Object
IJavaObjectEx.NeedsActivation IJavaObjectEx.NeedsActivation Inherited from Object
IJavaPeerable.JniManagedPeerState IJavaPeerable.JniManagedPeerState Inherited from Object
InetAddress InetAddress

Returns the IP address of the target host this socket is connected to, or null if this socket is not yet connected.

InputStream InputStream

Returns an input stream to read data from this socket.

IsBound IsBound

Returns whether this socket is bound to a local address and port.

IsClosed IsClosed

Returns whether this socket is closed.

IsConnected IsConnected

Returns whether this socket is connected to a remote host.

IsInputShutdown IsInputShutdown

Returns whether the incoming channel of the socket has already been closed.

IsOutputShutdown IsOutputShutdown

Returns whether the outgoing channel of the socket has already been closed.

JniIdentityHashCode JniIdentityHashCode Inherited from Object
JniPeerMembers JniPeerMembers
KeepAlive KeepAlive

Returns this socket's SoKeepalive setting.

LocalAddress LocalAddress

Returns the local IP address this socket is bound to, or an address for which IsAnyLocalAddress returns true if the socket is closed or unbound.

LocalPort LocalPort

Returns the local port this socket is bound to, or -1 if the socket is unbound.

LocalSocketAddress LocalSocketAddress

Returns the local address and port of this socket as a SocketAddress or null if the socket has never been bound.

OOBInline OOBInline

Returns this socket's SoOobinline setting.

OutputStream OutputStream

Returns an output stream to write data into this socket.

PeerReference PeerReference Inherited from Object
Port Port

Returns the port number of the target host this socket is connected to, or 0 if this socket is not yet connected.

ReceiveBufferSize ReceiveBufferSize

Returns this socket's SoRcvbuf.

RemoteSocketAddress RemoteSocketAddress

Returns the remote address and port of this socket as a SocketAddress or null if the socket is not connected.

ReuseAddress ReuseAddress

Returns this socket's SoReuseaddr setting.

SendBufferSize SendBufferSize

Returns this socket's SoSndbuf.

SoLinger SoLinger

Returns this socket's SoLinger timeout in seconds, or -1 for no linger (i.e.

SoTimeout SoTimeout

Returns this socket's SoTimeout.

TcpNoDelay TcpNoDelay

Returns this socket's SocketOptions#TCP_NODELAY setting.

ThresholdClass ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

TrafficClass TrafficClass

Returns this socket's setting.

Methods

Bind(SocketAddress) Bind(SocketAddress)

Binds this socket to the given local host address and port specified by the SocketAddress localAddr.

Clone() Clone()

Creates and returns a copy of this Object.

(Inherited from Object)
Close() Close()

Closes the socket.

Connect(SocketAddress) Connect(SocketAddress)

Connects this socket to the given remote host address and port specified by the SocketAddress remoteAddr.

Connect(SocketAddress, Int32) Connect(SocketAddress, Int32)

Connects this socket to the given remote host address and port specified by the SocketAddress remoteAddr with the specified timeout.

ConnectAsync(SocketAddress) ConnectAsync(SocketAddress)
ConnectAsync(SocketAddress, Int32) ConnectAsync(SocketAddress, Int32)
Dispose() Dispose() Inherited from Object
Dispose(Boolean) Dispose(Boolean) Inherited from Object
Equals(Object) Equals(Object)

Compares this instance with the specified object and indicates if they are equal.

(Inherited from Object)
GetHashCode() GetHashCode()

Returns an integer hash code for this object.

(Inherited from Object)
JavaFinalize() JavaFinalize()

Invoked when the garbage collector has detected that this instance is no longer reachable.

(Inherited from Object)
Notify() Notify()

Causes a thread which is waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

(Inherited from Object)
NotifyAll() NotifyAll()

Causes all threads which are waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

(Inherited from Object)
SendUrgentData(Int32) SendUrgentData(Int32)

Sends the given single byte data which is represented by the lowest octet of value as "TCP urgent data".

SendUrgentDataAsync(Int32) SendUrgentDataAsync(Int32)
SetHandle(IntPtr, JniHandleOwnership) SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetPerformancePreferences(Int32, Int32, Int32) SetPerformancePreferences(Int32, Int32, Int32)

Sets performance preferences for connectionTime, latency and bandwidth.

SetSocketImplFactory(ISocketImplFactory) SetSocketImplFactory(ISocketImplFactory)

Sets the internal factory for creating socket implementations.

SetSoLinger(Boolean, Int32) SetSoLinger(Boolean, Int32)

Sets this socket's SoLinger timeout in seconds.

ShutdownInput() ShutdownInput()

Closes the input stream of this socket.

ShutdownOutput() ShutdownOutput()

Closes the output stream of this socket.

ToArray<T>() ToArray<T>() Inherited from Object
ToString() ToString()

Returns a string containing a concise, human-readable description of this object.

(Inherited from Object)
UnregisterFromRuntime() UnregisterFromRuntime() Inherited from Object
Wait() Wait()

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.

(Inherited from Object)
Wait(Int64) Wait(Int64)

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

(Inherited from Object)
Wait(Int64, Int32) Wait(Int64, Int32)

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

(Inherited from Object)

Explicit Interface Implementations

IJavaObjectEx.ToLocalJniHandle() IJavaObjectEx.ToLocalJniHandle() Inherited from Object
IJavaPeerable.Disposed() IJavaPeerable.Disposed() Inherited from Object
IJavaPeerable.DisposeUnlessReferenced() IJavaPeerable.DisposeUnlessReferenced() Inherited from Object
IJavaPeerable.Finalized() IJavaPeerable.Finalized() Inherited from Object
IJavaPeerable.SetJniIdentityHashCode(Int32) IJavaPeerable.SetJniIdentityHashCode(Int32) Inherited from Object
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) Inherited from Object
IJavaPeerable.SetPeerReference(JniObjectReference) IJavaPeerable.SetPeerReference(JniObjectReference) Inherited from Object

Extension Methods

JavaCast<TResult>(IJavaObject) JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject) JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable) GetJniTypeName(IJavaPeerable)

Applies to