ØSends data asynchronously to a connected Socket object.
ØThe SendAsync method is used to write outgoing data from one or more buffers on a connection-oriented socket.
STEPS
1.
ØNamespace: System.Net.Sockets
Assembly: System.Net (in System.Net.dll)
C#
Øpublic bool SendAsync( SocketAsyncEventArgs args)
2.
ØSet up the SocketAsyncEventArgs object that will be used to connect the socket to the remote host.
•SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.UserToken =s;
args.RemoteEndPoint =ep;
3.
ØThe data is send on the socket by using encoding the data into a byte buffer
• Byte[] b = Encoding.UTF8.GetBytes(“My Data”);
4.
ØSetBuffer() function accepts a bytes array a byte array as 1st parameter,int offset as 2nd parameter ,and int length as 3rd parameter.
•args.SetBuffer(b,0, b.Lenth);
5.
ØOnSendCompleted() event handler to a SocketAsynEventArgs object
•args.Completed+= new EventHandler
6.
ØSendAsync() method of the socket object and pass the SocketAsynEventArgs object
•S.SendAsync(args);
7.
•When data is send to remote host the OnSendCompleted() event handler is called.
No comments:
Post a Comment