Click to See Complete Forum and Search --> : GetData for Socket


d-u
September 19th, 2005, 03:44 AM
I came across some nice classes of Socket but they don't have a 'GetData' as in winsock, could anybody help me out on making this method?

Socket1 Class (http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=144&lngWId=10)
Socket2 Class (http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=621&lngWId=10&txtForceRefresh=91920053425373629)

Alex F
September 19th, 2005, 07:00 AM
About first class: you need to subscribe to onDataArrival event and handle incoming data in event handler. Event has the following type:
Public Event onDataArrival(ByVal Data As Byte(), ByVal TotalBytes As Integer)

See wsClient_onDataArrival function in demo project. I guess second class works by similar way.

d-u
September 23rd, 2005, 11:27 PM
This is the code from VB6.0 which I am trying to convert...

Private Sub Socket_DataArrival(ByVal bytesTotal As Long)
Dim iPacket As String
Dim iCom As String
Dim iMessages As Integer

Socket.GetData iPacket ' - Pull Server Packet
iCom = Left$(iPacket, 1) ' - Grab 1st Character
RaiseEvent Noisy(iPacket) ' - Pass Reponse Via Event

If iCom = "+" Then GoTo GoodSub ' - If Good, Process Mail
If iCom = "-" Then GoTo BadSub ' - If Bad, Process Error

Exit Sub
GoodSub:

iMessages = 0

Select Case iState
Case 0
Socket.SendData "USER " & User & vbCrLf ' - USER INFORMATION
RaiseEvent Noisy("Sending USER...")
Case 1
Socket.SendData "PASS " & Password & vbCrLf ' - PASS INFORMATION
RaiseEvent Noisy("Sending PASS...")
Case 2
Socket.SendData "STAT" & vbCrLf ' - GETMAIL COMMAND
RaiseEvent Noisy("Checking Mail...")
Case 3
iMessages = CInt(Mid$(iPacket, 5, InStr(5, iPacket, " ") - 5)): Socket.SendData "QUIT" & vbCrLf
If iMessages = 0 Then RaiseEvent NoMail
If iMessages > 0 Then RaiseEvent NewMail(iMessages)
Case 4
Socket.CloseSck ' - CLOSE COMMAND
RaiseEvent Noisy("Closing Socket...")
Case Else
End Select

' Next Stage of Mail
iState = iState + 1

Exit Sub
BadSub:
RaiseEvent SockError("POP Error: " & iPacket)
End Sub

How can I go about it?