|
-
Jun 18th, 2003, 03:17 AM
#1
Thread Starter
Addicted Member
Winsock [RESOLVED]
I am trying to get to grips with winsock (I feel it is about time).
I have create a client and put the connect, send and close commands behind different button click events and it works fine, but when i come to try to do it behind one click event no data is sent. I don’t get any errors but no data is sent to the server app.
Any suggestions please.
VB Code:
Private Sub Command1_Click()
Dim count As Integer
Dim iData(1 To 4096) As Byte
Dim J As Long
Dim InputLength As Long
If winsock1.State <> sckClosed Then winsock1.Close
winsock1.Connect
iData(1) = 1
iData(2) = 4
iData(3) = 0
iData(4) = 4
iData(5) = 0
iData(6) = 2
iData(7) = 48
iData(8) = 10
Do Until winsock1.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If winsock1.State = sckError Then
MsgBox "No connection"
Exit Sub
End If
Loop
For J = 1 To 8
winsock1.SendData (iData(J))
Next
winsock1.Close
End Sub
Last edited by mik706; Jun 18th, 2003 at 04:26 AM.
Mik706
-
Jun 18th, 2003, 04:29 AM
#2
Thread Starter
Addicted Member
If anyone is interested i have solved the problem by putting a delay in after the send command:
VB Code:
Private Sub Command5_Click()
Dim count As Integer
Dim iData(1 To 4096) As Byte
Dim J As Long
Dim InputLength As Long
If winsock1.State <> sckClosed Then winsock1.Close
winsock1.Connect
iData(1) = 1
iData(2) = 4
iData(3) = 0
iData(4) = 4
iData(5) = 0
iData(6) = 2
iData(7) = 48
iData(8) = 10
Do Until winsock1.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If winsock1.State = sckError Then
MsgBox "No Connection"
Exit Sub
End If
Loop
For J = 1 To 8
winsock1.SendData (iData(J))
Next
For count = 1 To 32000
DoEvents
Next
winsock1.Close
End Sub
-
Jun 18th, 2003, 04:47 AM
#3
Addicted Member
mik,
It would be neater if you use a timer to control it.
all the best,
leng wai
-
Jun 18th, 2003, 05:04 AM
#4
Thread Starter
Addicted Member
I have done, i put the example up before i changed to using a timer.
-
Jun 18th, 2003, 05:57 PM
#5
If it were me, i would break it up a little more:
VB Code:
Option Explicit
Dim blnSendComplete As Boolean
Dim blnSendDataOnConnect As Boolean ' This is here incase you connect for another reason
Private Sub Command5_Click()
If Winsock1.State <> sckClosed Then Winsock1.Close
blnSendDataOnConnect = True
Winsock1.Connect
End Sub
Private Function SendData()
Dim count As Integer
Dim iData(1 To 4096) As Byte
Dim J As Long
'Dim InputLength As Long EDIT: why is this here?
iData(1) = 1
iData(2) = 4
iData(3) = 0
iData(4) = 4
iData(5) = 0
iData(6) = 2
iData(7) = 48
iData(8) = 10
For J = 1 To 8
Winsock1.SendData (iData(J))
Do Until blnSendComplete
DoEvents
Loop
blnSendComplete = False
Next
Winsock1.Close
End Function
Private Sub Winsock1_Connect()
If blnSendDataOnConnect = True Then
SendData
End If
End Sub
Private Sub Winsock1_SendComplete()
blnSendComplete = True
End Sub
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|