help with winsock events

Hello, i have a problem with the events in a port when i want to connect from VB to another private system. At today, that connection was made for MSComm, but now, we have a network card and we want connect to the system via Winsock..., anybody can help me please?.

Private Sub MSComm1_OnComm()

Select Case MSComm1.CommEvent
Case comEvReceive
Buffer = Buffer + SIN_CARACT_NULOS(MSComm1.Input)

' connected?..., two enter
If InStr(Buffer, "CONNECT 1200/NONE") > 0 Then
Sleep (2000)
Buffer = ""
Salida = " " & vbCrLf
MSComm1.Output = Salida
Sleep (2000)
MSComm1.Output = Salida

'Login to private system
ElseIf InStr(Buffer, "SIGN ON:") > 0 Then
Buffer = ""
Salida = psw_g & vbCrLf
MSComm1.Output = Salida
Sleep (500)

'send command PH
ElseIf Right(Buffer, 1) = "*" And Not Comando_PH Then
Buffer = ""
Salida = "PH" & vbCrLf
MSComm1.Output = Salida
Comando_PH = True
Sleep (1500)

'First line of command PH
ElseIf Comando_PH And Len(Buffer) > 87 Then
'Clean buffer
Buffer = Mid(Buffer, 4, Len(Buffer))
llego_ok = crc16(Buffer)
If llego_ok Then
Reg(I) = Buffer
I = I + 1
'record is OK
Salida = "A" & vbCrLf
MSComm1.Output = Salida
Else
'Resend record
Salida = "X" & vbCrLf
MSComm1.Output = Salida
End If
Buffer = ""
Sleep (1000)
'if there are more records, i read them
ElseIf Comando_PH And Len(Buffer) > 84 Then
'clean buffer
Buffer = Mid(Buffer, 2, Len(Buffer))
llego_ok = crc16(Buffer)
If llego_ok Then
Reg(I) = Buffer
I = I + 1
End If
'record is OK
Salida = "A" & vbCrLf
MSComm1.Output = Salida
Buffer = ""
Sleep (1000)

'End of records
ElseIf Comando_PH And InStr(Buffer, "**") Then
Bajada_Finalizada = True
End If

Case comEventBreak
error_comm = "Break Received"
Case comEventCDTO
error_comm = "Carrier Detect Timeout"
Case comEventCTSTO
error_comm = "CTS Timeout"
Case comEventDCB
error_comm = "Error retrieving DCB"
Case comEventDSRTO
error_comm = "DSR Timeout"
Case comEventFrame
error_comm = "Framing Error"
Case comEventOverrun
error_comm = "Overrun Error"
Case comEventRxOver
error_comm = "Receive Buffer Overflow"
Case comEventRxParity
error_comm = "Parity Error"
Case comEventTxFull
error_comm = "Transmit Buffer Full"
Case Is > 1000
error_comm = MSComm1.CommEvent
End Select
End Sub
[3511 byte] By [athilavb] at [2007-11-18 13:39:35]
# 1 Re: help with winsock events
This is copy and pasted from a program of mine, so it isn't customized for your application, but should give you a good head start. WS1 = Winsock Control

WS1.RemoteHost = ServerAddress
WS1.RemotePort = ServerPort

ConnectState = WS1.State

WS1.Connect

Do Until WS1.State = 7 Or WS1.State = 9 Or WS1.State = 0

DoEvents

If ConnectState <> WS1.State Then

Select Case WS1.State

Case 1

txtStatus.Text = txtStatus.Text & "Opening Port" & vbCrLf

Case 3

txtStatus.Text = txtStatus.Text & "Connection Pending" & vbCrLf

Case 4

txtStatus.Text = txtStatus.Text & "Resolving Host" & vbCrLf

Case 5

txtStatus.Text = txtStatus.Text & "Host Resolved" & vbCrLf

Case 6

txtStatus.Text = txtStatus.Text & "Connecting..." & vbCrLf

Case 7

txtStatus.Text = txtStatus.Text & "Connection Established" & vbCrLf

Case 8

txtStatus.Text = txtStatus.Text & "Peer Closing Connection" & vbCrLf
WS1.Close
ConnectToServer = 0
LogDetail = LogDetail & "3|Peer Closed Connection|" & Now
If MaxError < 3 Then MaxError = 3
GoTo Done

Case 9

txtStatus.Text = txtStatus.Text & "Error Establishing Connection" & vbCrLf
WS1.Close
ConnectToServer = 0
LogDetail = LogDetail & "3|Error Establishing Connection|" & Now
If MaxError < 3 Then MaxError = 3
GoTo Done

End Select

ConnectState = WS1.State

DoEvents

End If

Loop

If WS1.State = 7 Then

StartTime = Time$

Do Until WSMessage <> "" Or DateDiff("s", Time$, StartTime) > 60

DoEvents

Loop

If DateDiff("s", Time$, StartTime) > 60 Then
txtStatus.Text = txtStatus.Text & "Server Not Responding..." & vbCrLf
WS1.Close
End If

WS1.SendData "IConnected!"
softwareguy at 2007-11-9 23:28:52 >