xodos
asked on
error in client/server in vb6
dear sir
i m making an client/server on visual basic 6
the client collects sysinfo and local ip and send it to the server ,
it is working now ,
when a new client appears on the network , it sends the information to the server ,
but when he disconnected , he stills appear on the server list box ,
i want to make it automatically update when the client disconnect ,
client code :
=======
Private Sub Command1_Click()
Call Winsock1.Connect("82.198.5 .122", 13164)
Winsock1.SendData GetOSDetails() & " at [" & Winsock1.LocalIP & "]"
End Sub
Private Function GetOSDetails()
Dim MsgEnd As String
Select Case SysInfo1.OSPlatform
Case 0
MsgEnd = "Unidentified"
Case 1
MsgEnd = "Windows 95, ver. " & CStr(SysInfo1.OSVersion) & _
"(" & CStr(SysInfo1.OSBuild) & ")"
Case 2
MsgEnd = "Windows NT, ver. " & CStr(SysInfo1.OSVersion) & _
"(" & CStr(SysInfo1.OSBuild) & ")"
End Select
GetOSDetails = "[" & MsgEnd & "]"
End Function
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Winsock1.SendData "ShutDown " & Winsock1.LocalIP
End Sub
server code :
========
Private Sub Form_Load()
Winsock1.Bind 13164
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim s As String
Dim sender As String
Call Winsock1.GetData(s, vbString, bytesTotal)
If UCase(Left(s, 8)) = "SHUTDOWN" Then
sender = GetSenderIP(s)
For i = 0 To List1.ListCount
If GetSenderIP(List1.List(i)) = sender Then
' Write the code to remove the item
End If
Next
Else
List1.AddItem s
End If
End Sub
Private Function GetSenderIP(ByVal ClientData As String) As String
' Pass the data recd from client to this function and return the IP address of the sender
' which is present at the end of the string
End Function
i m making an client/server on visual basic 6
the client collects sysinfo and local ip and send it to the server ,
it is working now ,
when a new client appears on the network , it sends the information to the server ,
but when he disconnected , he stills appear on the server list box ,
i want to make it automatically update when the client disconnect ,
client code :
=======
Private Sub Command1_Click()
Call Winsock1.Connect("82.198.5
Winsock1.SendData GetOSDetails() & " at [" & Winsock1.LocalIP & "]"
End Sub
Private Function GetOSDetails()
Dim MsgEnd As String
Select Case SysInfo1.OSPlatform
Case 0
MsgEnd = "Unidentified"
Case 1
MsgEnd = "Windows 95, ver. " & CStr(SysInfo1.OSVersion) & _
"(" & CStr(SysInfo1.OSBuild) & ")"
Case 2
MsgEnd = "Windows NT, ver. " & CStr(SysInfo1.OSVersion) & _
"(" & CStr(SysInfo1.OSBuild) & ")"
End Select
GetOSDetails = "[" & MsgEnd & "]"
End Function
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Winsock1.SendData "ShutDown " & Winsock1.LocalIP
End Sub
server code :
========
Private Sub Form_Load()
Winsock1.Bind 13164
End Sub
Private Sub Winsock1_DataArrival(ByVal
Dim s As String
Dim sender As String
Call Winsock1.GetData(s, vbString, bytesTotal)
If UCase(Left(s, 8)) = "SHUTDOWN" Then
sender = GetSenderIP(s)
For i = 0 To List1.ListCount
If GetSenderIP(List1.List(i))
' Write the code to remove the item
End If
Next
Else
List1.AddItem s
End If
End Sub
Private Function GetSenderIP(ByVal ClientData As String) As String
' Pass the data recd from client to this function and return the IP address of the sender
' which is present at the end of the string
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you only need to remove the item from the list box if the "shutdown ..." message is received? In that case:
> Private Sub Form_Load()
> Winsock1.Bind 13164
> End Sub
>
> Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
> Dim s As String
> Dim sender As String
> Call Winsock1.GetData(s, vbString, bytesTotal)
!!! If UCase(Left(s, 8)) = "SHUTDOWN" Then ' <<< You need the space at the end, if we accidentally get the message 'shutdown' (8 chars only),
we won't be able to remove the first 9 characters
* If Ucase(Left(s,9))="SHUTDOWN " Then
> sender = GetSenderIP(s)
!!! For i = 0 To List1.ListCount ' <<< item # List1.Listcount does not exist; corrected below
* For i = 0 To List1.ListCount - 1
> If GetSenderIP(List1.List(i)) = sender Then
> ' Write the code to remove the item
* List1.RemoveItem i
> End If
> Next
> Else
> List1.AddItem s
> End If
> End Sub
> Private Function GetSenderIP(ByVal ClientData As String) As String
> ' Pass the data recd from client to this function and return the IP address of the sender
> ' which is present at the end of the string
* GetSenderIP = Right(ClientData, Len(ClientData)-9)
> End Function
Is it ok?
> Private Sub Form_Load()
> Winsock1.Bind 13164
> End Sub
>
> Private Sub Winsock1_DataArrival(ByVal
> Dim s As String
> Dim sender As String
> Call Winsock1.GetData(s, vbString, bytesTotal)
!!! If UCase(Left(s, 8)) = "SHUTDOWN" Then ' <<< You need the space at the end, if we accidentally get the message 'shutdown' (8 chars only),
we won't be able to remove the first 9 characters
* If Ucase(Left(s,9))="SHUTDOWN
> sender = GetSenderIP(s)
!!! For i = 0 To List1.ListCount ' <<< item # List1.Listcount does not exist; corrected below
* For i = 0 To List1.ListCount - 1
> If GetSenderIP(List1.List(i))
> ' Write the code to remove the item
* List1.RemoveItem i
> End If
> Next
> Else
> List1.AddItem s
> End If
> End Sub
> Private Function GetSenderIP(ByVal ClientData As String) As String
> ' Pass the data recd from client to this function and return the IP address of the sender
> ' which is present at the end of the string
* GetSenderIP = Right(ClientData, Len(ClientData)-9)
> End Function
Is it ok?
See here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mswnsk98/dt_vbobjWinsockControl_E.asp
for more information.
-