| Whenever you are using the Winsock, no doubt you'll be sending strings and other data across an open connection. However, occasioanlly, for one reason or another, your connection will close, and you won't know about it. If you then try to send data across that connection, your program will error and die. To solve this, I wrote a generic function to use, so that data is always sent safely. If data is sent fine, it returns true, if there's an error, it returns false. Public Function WinsockSend(pSock As Winsock, ByVal Data As String) ' send the data on the passed winsock If pSock.State = sckConnected Then ' send the data and return true pSock.SendData Data DoEvents WinsockSend = True Else ' return false because we're not connected WinsockSend = False End If End Function If I had a Winsock called sckMain I would call it like this: ' instead of using this to send data If sckMain.State = sckConnected Then sckMain.SendData strData DoEvents End If ' i can use this blnRetVal = WinsockSend(sckMain, strData) Then after you've made the call to WinsockSend, you can check the value of blnRetVal to see if the send was successful or not. Simple. |
Safely Send A String |
Freelance ASP PHP web development | Web developer India Web development India| Prayagasoft - web designer India, Ecommerce developer india, Ecommerce design