losingsleeep
losingsleeep

Reputation: 1879

How to ensure of Socket sent data?

In .NET CF on a Windows CE 5.0 based POS device, if no connection (GPRS/WiFi) is available, when i try to connect my socket object i don't get any exceptions, even after it, when i try to send bytes to somewhere by Socket.SentTo() method i don't get any exceptions too! And even the returned value indicating the size of totally sent bytes is correct! what's the matter? how can i ensure of the health of the operations? pieces of my code:

Socket m_socClient = new Socket(
  AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress ipAdd = IPAddress.Parse("192.168.7.80");
IPEndPoint remoteEP = new IPEndPoint(ipAdd, 2415);
m_socClient.Connect(remoteEP); // No exception!

// why works?
int iSent = m_socClient.SendTo(byData, byData.Length, 
     SocketFlags.None, remoteEP);

Upvotes: 2

Views: 358

Answers (1)

PaulG
PaulG

Reputation: 14021

Few suggestions:

  • Check the Connected property of the connection

  • I understand SendTo is more suited for connectionless protocols, and Send() is better suited for Connection-oriented protocols like TCP.

  • Send() (and I expect SendTo()) may have no effect if there is no data to send. Have you checked there is data?

Upvotes: 1

Related Questions