hello!
how can i send data? (server to all clients)
1. open 3 clients
2. close client1 (of course use for loop 1 to 3 and send to all)
3. i have condition in clents if recieved ("Close") then End/unload
4. open again client1
5. you can's use for loop again because 1 can't find because i closed it before
how to use my index then?
in the server winsock(0)
tnx
2 1320
Can you post your code for reference of our experts please.
'client side -
Private Sub Winsock1_Close()
-
On Error Resume Next
-
Label3.Caption = ""
-
Winsock1.Close
-
Winsock1.Connect txtIP.Text, 1007
-
End Sub
-
-
Private Sub Winsock1_Connect()
-
Label4.Caption = "Connected"
-
Winsock1.SendData txtName.Text + "|" + Winsock1.LocalIP + "|" + Winsock1.LocalHostName
-
End Sub
-
-
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
-
Dim sData As String
-
-
Winsock1.GetData sData, vbString
-
Winsock1.SendData "from " + txtName.Text + " - " + sData + "|" + "|"
-
'Label1.Caption = sData
-
txtPrice.Text = sData
-
Label3.Caption = "Received Data"
-
shpGo.Visible = True
-
shpWait.Visible = False
-
shpError.Visible = False
-
If sData = txtName.Text Then
-
Winsock1.Close
-
End
-
ElseIf sData = "Disconnected" Then
-
Winsock1.Close
-
Label4.Caption = "Disconnected"
-
End If
-
End Sub
-
-
Private Sub Winsock1_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)
-
Winsock1.Close
-
Winsock1.Connect txtIP.Text, 1007
-
'Label4.Caption = "Disconnected1 " + err.Description
-
End Sub
-
-
-
Private Sub Timer1_Timer()
-
On Error GoTo err
-
If Winsock1.State <> 7 Then
-
Winsock1.Close
-
Winsock1.Connect txtIP.Text, 1007
-
Label4.Caption = "Disconnected2 " '+ Winsock1.State
-
End If
-
Exit Sub
-
err:
-
Winsock1.Close
-
Label4.Caption = "Disconnected " '+ CStr(Winsock1.State)
-
'MsgBox Winsock1.State
-
End Sub
-
'server side -
Private Sub cmdPC_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, Y As Single)
-
If Button = vbRightButton Then
-
cmdPC(Index).SetFocus
-
sClientName = cmdPC(Index).Caption
-
idxPC = Index
-
idxSocket = Index
-
PopupMenu mnu
-
End If
-
End Sub
-
-
Private Sub mnuClose_Click()
-
Dim i As Long
-
-
'For i = 1 To iSockets
-
If Socket(idxPC).State = sckConnected Then
-
If cmdPC(idxPC).Enabled = True Then
-
Socket(idxPC).SendData sClientName
-
cmdPC(idxPC).Enabled = False
-
List1.AddItem "send to: " + CStr(Socket(idxPC)) + "-" + sClientName
-
Else
-
MsgBox "client is not connected"
-
End If
-
End If
-
'Next
-
End Sub
-
-
Private Sub Form_Load()
-
lblHostID.Caption = Socket(0).LocalHostName
-
lblAddress.Caption = Socket(0).LocalIP
-
Socket(0).LocalPort = 1007
-
sServerMsg = "Listening to port: " & Socket(0).LocalPort
-
List1.AddItem (sServerMsg)
-
Socket(0).Listen
-
End Sub
-
-
Private Sub socket_Close(Index As Integer)
-
sServerMsg = "Connection closed: " & Socket(idxPC).RemoteHostIP
-
List1.AddItem (sServerMsg)
-
Socket(idxPC).Close
-
Unload Socket(idxPC)
-
cmdPC(idxPC).Enabled = False
-
iSockets = iSockets - 1
-
lblConnections.Caption = iSockets
-
End Sub
-
-
Private Sub socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
-
On Error GoTo err
-
sServerMsg = "Connection request id " & requestID & " from " & Socket(Index).RemoteHostIP
-
-
If Index = 0 Then
-
'List1.AddItem (sServerMsg)
-
sRequestID = requestID
-
If err.Number = 360 Then
-
Socket(0).Close
-
Socket(0).Listen
-
End If
-
iSockets = iSockets + 1
-
lblConnections.Caption = iSockets
-
Load Socket(iSockets)
-
'Load Socket(Socket.UBound + 1)
-
Socket(iSockets).LocalPort = 1007
-
Socket(iSockets).Accept requestID
-
Label1.Caption = ""
-
End If
-
-
Exit Sub
-
err:
-
Socket(0).Close
-
Socket(0).Listen
-
iSockets = 0
-
'iSockets = iSockets - 1
-
Label1.Caption = CStr(err.Number) + " " + err.Description + "-" + sClientName
-
End Sub
-
-
Private Sub socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
-
Socket(Index).GetData strReceived
-
strSplit() = Split(strReceived, "|")
-
sClientName = strSplit(0)
-
strIP = strSplit(1)
-
strHostName = strSplit(2)
-
txtClientName.Text = sClientName
-
txtHostName.Text = strHostName
-
txtIP.Text = strIP
-
List1.AddItem (sServerMsg + "-" + sClientName)
-
Select Case (sClientName)
-
Case "PC1"
-
Index = 1
-
cmdPC(Index).Enabled = True
-
Case "PC2"
-
Index = 2
-
cmdPC(Index).Enabled = True
-
Case "PC3"
-
Index = 3
-
cmdPC(Index).Enabled = True
-
End Select
-
End Sub
-
hope it will help, with simple server and 1 client there is no problem
but server and many clients kinda tricky...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mtc |
last post by:
hi...
how to add the winsock to the vb.net smart device application??
i try it before...but the system say" this is not .net assembly"
so what should i do to add winsock as references??
|
by: Paul |
last post by:
Hello,
I nead to create chat server but i cannot find any sample can you show me
how i can craete multirhread chat server. ??
Regards
PM
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |