ishrar
Mar 18th, 2007, 01:36 AM
Hello friends I have wrote some code for connecting through winsock to send data, but there is problem in connecting, whenever i connect it is connected for 1 second after that its state is clossing. I dont how this problem occures.
So please try to help me
Private Sub cmdConn_Click()
If Not txtPort = "" Or Not txtIp.Text = "" Then
wskSend.Close
DoEvents
wskSend.RemoteHost = txtIp.Text
wskSend.RemotePort = Val(txtPort.Text)
'MsgBox wskSend.State
wskSend.Connect
'MsgBox wskSend.State
End If
End Sub
Private Sub cmdSend_Click()
On Error GoTo sol
Label4.Caption = wskSend.State
If Not wskSend.State = 7 Then
wskSend.Connect
End If
wskSend.SendData txtMsg
Exit Sub
sol:
MsgBox Err.Description
End Sub
'Close connection button
Private Sub Command1_Click()
wskSend.Close
End Sub
Private Sub Form_Load()
wskSend.Protocol = sckTCPProtocol
End Sub
Private Sub Timer1_Timer()
If wskSend.State = 6 Then
Label4.Caption = "Connecting"
ElseIf wskSend.State = 7 Then
Label4.Caption = "Connected"
MsgBox "connected"
ElseIf wskSend.State = 0 Then
Label4.Caption = "Closed"
ElseIf wskSend.State = 8 Then
Label4.Caption = "Clossing"
'MsgBox "closing"
'wskSend.Close
ElseIf wskSend.State = 9 Then
Label4.Caption = "Error"
ElseIf wskSend.State = 2 Then
Label4.Caption = "Listening"
ElseIf wskSend.State = 1 Then
Label4.Caption = "Open"
ElseIf wskSend.State = 7 Then
Label4.Caption = "Connected"
End If
End Sub
Private Sub wskSend_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Error in connection" & Number & Description
End Sub
Private Sub wskSend_SendComplete()
Label4.Caption = "data sent"
End Sub
Private Sub wskSend_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
Label4.Caption = "sending"
End Sub
So please try to help me
Private Sub cmdConn_Click()
If Not txtPort = "" Or Not txtIp.Text = "" Then
wskSend.Close
DoEvents
wskSend.RemoteHost = txtIp.Text
wskSend.RemotePort = Val(txtPort.Text)
'MsgBox wskSend.State
wskSend.Connect
'MsgBox wskSend.State
End If
End Sub
Private Sub cmdSend_Click()
On Error GoTo sol
Label4.Caption = wskSend.State
If Not wskSend.State = 7 Then
wskSend.Connect
End If
wskSend.SendData txtMsg
Exit Sub
sol:
MsgBox Err.Description
End Sub
'Close connection button
Private Sub Command1_Click()
wskSend.Close
End Sub
Private Sub Form_Load()
wskSend.Protocol = sckTCPProtocol
End Sub
Private Sub Timer1_Timer()
If wskSend.State = 6 Then
Label4.Caption = "Connecting"
ElseIf wskSend.State = 7 Then
Label4.Caption = "Connected"
MsgBox "connected"
ElseIf wskSend.State = 0 Then
Label4.Caption = "Closed"
ElseIf wskSend.State = 8 Then
Label4.Caption = "Clossing"
'MsgBox "closing"
'wskSend.Close
ElseIf wskSend.State = 9 Then
Label4.Caption = "Error"
ElseIf wskSend.State = 2 Then
Label4.Caption = "Listening"
ElseIf wskSend.State = 1 Then
Label4.Caption = "Open"
ElseIf wskSend.State = 7 Then
Label4.Caption = "Connected"
End If
End Sub
Private Sub wskSend_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Error in connection" & Number & Description
End Sub
Private Sub wskSend_SendComplete()
Label4.Caption = "data sent"
End Sub
Private Sub wskSend_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
Label4.Caption = "sending"
End Sub