Back to product page

SendData method


Sends byte array message to remote peer.

Type

Integer.

Syntax

  • C#
  • C++
  • VB.NET
int devP2P.SendData(IntPtr Handle, int chanid, string data, int len, bool reliable);
The SendData(Handle,chanid,data,len,reliable) syntax has these parts:
HandleReference to the devP2P instance.
chanidInteger that specifies channel index.
dataString with data.
lenTotal number of bytes to send.
reliableDetermines if packet should be delivered in reliable way. Defaults to true.
Return value0 (ErrorNone) if success, otherwise negative value from Errors enumeration.

int SendData(int chanid, char *data, int len, bool reliable = true);
The SendData(chanid,data,len,reliable) syntax has these parts:
chanidInteger that specifies channel index.
dataPointer to allocated memory where data is stored.
lenLength of data buffer to send.
reliableDetermines if packet should be delivered in reliable way. Defaults to true.
Return value0 (ErrorNone) if success, otherwise negative value from Errors enumeration.

Function P2P_SendData(ByVal Handle As IntPtr, ByVal chanid As Integer, ByVal data As String, ByVal len As Integer, ByVal reliable As Boolean) As Integer
The SendData(Handle,chanid,data,len,reliable) syntax has these parts:
HandleReference to the devP2P instance.
chanidInteger that specifies channel index.
dataString with data.
lenTotal number of bytes to send.
reliableDetermines if packet should be delivered in reliable way. Defaults to true.
Return value0 (ErrorNone) if success, otherwise negative value from Errors enumeration.

Remarks

SendData will send byte array to remote peer. On peer's side, DataReceived event will fire when byte array arrives. You can use this method only after connection with remote peer is established, of course.

You should select one of 1024 available channels to send this message. Make sure that channel is not already used by file transfer, or channel forwarding. You can send more than one message through the channel, so usually you can pick channel 0 for messages of any kind.

If you did not specify reliable method, it is possible packet never reaches the destination. This makes sense for information that is not important and possibly will be resent (such as some status information you want to provide to remote side).

You will not get any confirmation that your message is delivered.

Platforms

Windows
Mac OSX
Linux
BSD