开发者

How to ensure of Socket sent data?

开发者 https://www.devze.com 2023-03-11 04:19 出处:网络
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

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);


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消