Home > Software engineering >  Regarding the sock connection
Regarding the sock connection

Time:09-16

Private Sub DO2_1 ()
Dim connectFiag As Boolean
Dim fx () As Byte
ConnectFiag=False
If Not connectFiag Then
Sckconnect1. Close
Sckconnect1. Connect "10.22.172.147", 502,
Do
DoEvents
Loop Until sckconnect1. State=sckConnected
ConnectFiag=True
End the If

ReDim fx (11)
Fx (0)=& amp; H0
Fx (1)=& amp; H1
Fx (2)=& amp; H0
Fx (3)=& amp; H0
Fx (4)=& amp; H0
Fx (5)=& amp; H6
Fx (6)=& amp; HFF
Fx (7)=& amp; H5
Fx (8)=& amp; H0
Fx (9)=& amp; H65
Fx (10)=& amp; HFF
Fx (11)=& amp; H0
Sckconnect1. SendData publishes the event fx
sckconnect1. Close
End Sub


Private Sub DO1_0 ()
Dim connectFiag As Boolean
Dim fx () As Byte
ConnectFiag=False
If Not connectFiag Then
Sckconnect1. Close
Sckconnect1. Connect "10.22.172.147", 502,
Do
DoEvents
Loop Until sckconnect1. State=sckConnected
ConnectFiag=True
End the If

ReDim fx (11)
Fx (0)=& amp; H0
Fx (1)=& amp; H1
Fx (2)=& amp; H0
Fx (3)=& amp; H0
Fx (4)=& amp; H0
Fx (5)=& amp; H6
Fx (6)=& amp; HFF
Fx (7)=& amp; H5
Fx (8)=& amp; H0
Fx (9)=& amp; H64
Fx (10)=& amp; H0
Fx (11)=& amp; H0
Sckconnect1. SendData publishes the event fx
sckconnect1. Close

End Sub


Private Sub Command2_Click ()
Call DO1_1
End Sub

Private Sub Command3_Click ()
Call DO1_0
End Sub


Can someone help me to look at? sckconnect1. Close add in this sentence, is executed is not successful, delete can run normally
Sckconnect1. Close used here can not be like this? Consult ace ~ ~ ~ ~ ~ ~ ~

CodePudding user response:

Certainly not!
"Network" is a time delay, is "low", and in most cases is asynchronous operations (you use "control object must be asynchronous operations),
You perform sckconnect1. SendData publishes the event is just the pipeline data, and related information submitted, is not "done immediately send",
The "statement" is immediately returned after execution, data "for appropriate time to send again, just a moment,"
You're sckconnect1. Perform sckconnect1 immediately after SendData publishes the event. The Close, the connection is disconnected immediately, data must not go out,

CodePudding user response:

Gracefully closes the connection is closed after receiving a specific information,

CodePudding user response:

Gracefully closes the connection is closed after receiving a specific information,

CodePudding user response:


HMM. Like building a great god said.

There should be a send complete event ceng ceng points...

CodePudding user response:

I put the sckconnect1. Close to delete, can run normally,

But two days later I went to see, the program had no reaction, I use sckconnect1 state property looked at it and found that the value is 9, is sckError, in addition I is controlled by the timer control,

How does this change process? Pray god give a train of thought

CodePudding user response:

Ah, it is said he can't finish immediately shut down, not said not to close,
If you don't shut down, then the connection will be kept, until the broken network, the server disconnected, the server service is down... Connection is broken, and so on result,
You should confirm the data is sent, the other side also received the information, it is not necessary to continue to send again close in time,

CodePudding user response:

Add a Timer to monitor network sends the disconnect
The Select Case Winsock1. State
Case 0
Label1. Caption="status: closed"
Case 1
Label1. Caption="status: open"
Case 2
Label1. Caption="state: listen for"
Case 3
Label1. Caption="status: connection hang"
Case 4
Label1. Caption="state: identify the host"
Case 5
Label1. Caption="status: the identified host"
Case 6
Label1. Caption="state: connecting"
Case 7
Label1. Caption="connected:
"Case 8
Label1. Caption="personnel are close the connection at the same level:"
Case 9
Label1. Caption="status: error"
End the Select

CodePudding user response:

May I ask which states sent out upstairs?

CodePudding user response:

Close after each other send to receive complete information

CodePudding user response:

I temporarily in sendComplete event delay shut down after 5 seconds, while also success
But I find the most appropriate method should be accept to return to the command and then shut down
I was with a network communication module, the specification of this equipment if said equipment normal after executing the command, will return the data "000100000006 ff0f00640002
"How do I receive the data?

CodePudding user response:

There are superior in?

CodePudding user response:

Fyi:
 Dim after the As a Double 
Dim strTotal (11) as Byte
Dim as Long s

Sckconnect1. SendData publishes the event fx
'sckconnect1. Close
After Now + 10=#/24 #/3600 #
Do
DoEvents
If sckconnect1. State=0 Then Exit the Do
If Now & gt; After Then
Sckconnect1. Close
The Exit Do
End the If
Loop



Private Sub sckconnect1_DataArrival (ByVal bytesTotal As Long)
Dim strData () As Byte
Dim As Long I
Dim hexstr As String
On the Error Resume Next
ReDim strData (bytesTotal - 1)
Sckconnect1. GetData strData
For I=0 to bytesTotal - 1
If s + i<12 Then strTotal (s + I)=strData (I) the else exit for
Next
S=s + I
If s> 12 then=
For I=0 to 11
Hexstr=hexstr & amp; Right (" 0 "& amp; Hex (strTotal (I)), 2)
Next
If hexstr="000100000006 ff0f00640002" Then sckconnect1. Close
End the if
End Sub

CodePudding user response:

This looks very difficult, even if can pass, in practice, also can appear stuck,
  • Related