home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD5443522000.psc / CHAT_FUN.BAS < prev    next >
Encoding:
BASIC Source File  |  2000-05-02  |  6.3 KB  |  118 lines

  1. Attribute VB_Name = "CHAT_Functions"
  2. Option Explicit
  3. Public Sub InitServerList(ServerList As ComboBox)
  4.     ' Populate Server List Box...
  5.     ServerList.AddItem "127.0.0.1"
  6.     ServerList.AddItem "VBLABWK3"
  7.     ServerList.AddItem "VBLABWK9"
  8. End Sub
  9.  
  10. '--------------------------------------------------------------
  11. Public Sub DebugSocket(TCPSocket As Winsock)
  12. ' Prints Information In A TCP Socket, For Debugging TCP Events...
  13. '--------------------------------------------------------------
  14.     Debug.Print "TCPSocket.RemoteHost", TCPSocket.RemoteHost
  15.     Debug.Print "TCPSocket.RemoteHostIP", TCPSocket.RemoteHostIP
  16.     Debug.Print "TCPSocket.RemotePort", TCPSocket.RemotePort
  17.     Debug.Print "TCPSocket.LocalHostName", TCPSocket.LocalHostName
  18.     Debug.Print "TCPSocket.LocalIP", TCPSocket.LocalIP
  19.     Debug.Print "TCPSocket.LocalPort", TCPSocket.LocalPort
  20.     Debug.Print "TCPSocket.State", TCPSocket.State
  21.     Debug.Print "====================================================="
  22. '--------------------------------------------------------------
  23. End Sub
  24. '--------------------------------------------------------------
  25.  
  26. '------------------------------------------------------------------
  27. Public Sub ResPlaySound(ResourceId As Long)
  28. ' Uses Sound Play Sound To Play Back PreRecorded WaveFiles
  29. '------------------------------------------------------------------
  30.     Dim sndBuff As String
  31. '------------------------------------------------------------------
  32.     sndBuff = StrConv(LoadResData(ResourceId, "WAVE"), vbUnicode)
  33.     Call sndPlaySound(sndBuff, SND_SYNC Or SND_MEMORY)
  34. '------------------------------------------------------------------
  35. End Sub
  36. '------------------------------------------------------------------
  37.  
  38. '--------------------------------------------------------------
  39. Public Sub AddConnectionToList(Socket As Winsock, ConnList As ListBox)
  40. ' Adds A Connection Reference To A ListBox - [(Server)(LocalPort)(RemotePort)]
  41. '--------------------------------------------------------------
  42.     Dim MemberID As String                      ' Connection Reference Variable
  43. '--------------------------------------------------------------
  44.     ' Create MemberID From HostName and RemoteIP
  45.     MemberID = Socket.RemoteHostIP & "  [" & _
  46.                Format(Socket.RemotePort, "0") & "] - [" & _
  47.                Format(Socket.LocalPort, "0") & "]"
  48.  
  49.     ConnList.AddItem MemberID                   ' Add New Member To List
  50.     ConnList.ItemData(ConnList.NewIndex) = Socket.Index
  51. '--------------------------------------------------------------
  52. End Sub
  53. '--------------------------------------------------------------
  54.  
  55. '--------------------------------------------------------------
  56. Public Sub RemoveConnectionFromList(Socket As Winsock, ConnList As ListBox)
  57. ' Removes A Connection Reference From A ListBox
  58. '--------------------------------------------------------------
  59.     Dim Conn As Long                                ' Connection Array Element Variable
  60.     Dim MemberID As String                          ' Connection Reference Variable
  61. '--------------------------------------------------------------
  62.     ' Create MemberID From HostName and RemoteIP
  63.     MemberID = Socket.RemoteHostIP & "  [" & _
  64.                Format(Socket.RemotePort, "0") & "] - [" & _
  65.                Format(Socket.LocalPort, "0") & "]"
  66.     
  67.     For Conn = 0 To ConnList.ListCount - 1          ' Search Each Member In List
  68.         If (ConnList.List(Conn) = MemberID) Then    ' Look For MemberID In List
  69.             ConnList.RemoveItem Conn                ' Remove MemberID From List
  70.         End If
  71.     Next                                            ' Next Connection
  72. '--------------------------------------------------------------
  73. End Sub
  74. '--------------------------------------------------------------
  75.  
  76. '--------------------------------------------------------------
  77. Public Sub GetIdxFromMemberID(Sockets As Variant, MemberID As String, Index As Long)
  78. '--------------------------------------------------------------
  79.     Dim Idx As Long                                 ' Socket cntl index
  80.     Dim LocPortID As Long                           ' Local Port ID
  81.     Dim RemPortID As Long                           ' Remote Port ID
  82.     Dim RemoteIP As String                          ' Remote Host IP address
  83.     Dim sStart As Long                              ' Substring begin position
  84.     Dim sEnd As Long                                ' Substring end postition
  85.     Dim Socket As Winsock                               ' Winsock socket
  86. '--------------------------------------------------------------
  87.     sStart = 1
  88.     sEnd = InStr(1, MemberID, " ") - 1              ' Get end of remote ip address
  89.     If (sEnd > 1) Then
  90.         RemoteIP = Mid(MemberID, sStart, sEnd)      ' Get remote host ip address
  91.         sStart = InStr(sEnd, MemberID, "[") + 1     ' Get start of remote port
  92.         If (sStart > 1) Then                        ' If Start found
  93.             sEnd = InStr(sStart, MemberID, "]") - 1 ' Get end of remote port
  94.             If (sEnd > 2) Then                      ' If end found
  95.                 RemPortID = Val(Mid(MemberID, sStart, sEnd)) ' Get RemotePort
  96.                 sStart = InStr(sEnd, MemberID, "[") + 1      ' Get start of local port
  97.                 If (sStart > 1) Then
  98.                     sEnd = InStr(sStart, MemberID, "]") - 1  ' Get end of local port
  99.                     If (sEnd > 2) Then                       ' If End Found
  100.                         LocPortID = Val(Mid(MemberID, sStart, sEnd)) ' Extract local port
  101.                         For Each Socket In Sockets
  102.                             If ((Socket.RemoteHostIP = RemoteIP) And _
  103.                                 (Socket.RemotePort = RemPortID) And _
  104.                                 (Socket.LocalPort = LocPortID) And _
  105.                                 (Socket.Index > 0)) Then    ' Was a match found???
  106.                                 Index = Socket.Index        ' Save and return index
  107.                                 Exit Sub                    ' Done... exit
  108.                             End If
  109.                         Next
  110.                     End If
  111.                 End If
  112.             End If
  113.         End If
  114.     End If
  115. '--------------------------------------------------------------
  116. End Sub
  117. '--------------------------------------------------------------
  118.