473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

wisock

basti42
18
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
Feb 27 '08 #1
2 1320
debasisdas
8,127 Expert 4TB
Can you post your code for reference of our experts please.
Feb 27 '08 #2
basti42
18
'client side
Expand|Select|Wrap|Line Numbers
  1. Private Sub Winsock1_Close()
  2. On Error Resume Next
  3.  Label3.Caption = ""
  4.  Winsock1.Close
  5.  Winsock1.Connect txtIP.Text, 1007
  6. End Sub
  7.  
  8. Private Sub Winsock1_Connect()
  9.  Label4.Caption = "Connected"
  10.  Winsock1.SendData txtName.Text + "|" + Winsock1.LocalIP + "|" + Winsock1.LocalHostName
  11. End Sub
  12.  
  13. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  14. Dim sData As String
  15.  
  16. Winsock1.GetData sData, vbString
  17. Winsock1.SendData "from " + txtName.Text + " - " + sData + "|" + "|"
  18. 'Label1.Caption = sData
  19. txtPrice.Text = sData
  20. Label3.Caption = "Received Data"
  21. shpGo.Visible = True
  22. shpWait.Visible = False
  23. shpError.Visible = False
  24.  If sData = txtName.Text Then
  25.   Winsock1.Close
  26.   End
  27.  ElseIf sData = "Disconnected" Then
  28.   Winsock1.Close
  29.   Label4.Caption = "Disconnected"
  30.  End If
  31. End Sub
  32.  
  33. 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)
  34.  Winsock1.Close
  35.  Winsock1.Connect txtIP.Text, 1007
  36.  'Label4.Caption = "Disconnected1 " + err.Description
  37. End Sub
  38.  
  39.  
  40. Private Sub Timer1_Timer()
  41. On Error GoTo err
  42.  If Winsock1.State <> 7 Then
  43.    Winsock1.Close
  44.    Winsock1.Connect txtIP.Text, 1007
  45.    Label4.Caption = "Disconnected2 " '+ Winsock1.State
  46.  End If
  47.  Exit Sub
  48. err:
  49. Winsock1.Close
  50. Label4.Caption = "Disconnected " '+ CStr(Winsock1.State)
  51. 'MsgBox Winsock1.State
  52. End Sub
  53.  
'server side
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPC_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, Y As Single)
  2.  If Button = vbRightButton Then
  3.   cmdPC(Index).SetFocus
  4.   sClientName = cmdPC(Index).Caption
  5.   idxPC = Index
  6.   idxSocket = Index
  7.   PopupMenu mnu
  8.  End If
  9. End Sub
  10.  
  11. Private Sub mnuClose_Click()
  12. Dim i As Long
  13.  
  14. 'For i = 1 To iSockets
  15.  If Socket(idxPC).State = sckConnected Then
  16.    If cmdPC(idxPC).Enabled = True Then
  17.      Socket(idxPC).SendData sClientName
  18.      cmdPC(idxPC).Enabled = False
  19.      List1.AddItem "send to: " + CStr(Socket(idxPC)) + "-" + sClientName
  20.    Else
  21.      MsgBox "client is not connected"
  22.    End If
  23.  End If
  24. 'Next
  25. End Sub
  26.  
  27. Private Sub Form_Load()
  28.     lblHostID.Caption = Socket(0).LocalHostName
  29.     lblAddress.Caption = Socket(0).LocalIP
  30.     Socket(0).LocalPort = 1007
  31.     sServerMsg = "Listening to port: " & Socket(0).LocalPort
  32.     List1.AddItem (sServerMsg)
  33.     Socket(0).Listen
  34. End Sub
  35.  
  36. Private Sub socket_Close(Index As Integer)
  37.     sServerMsg = "Connection closed: " & Socket(idxPC).RemoteHostIP
  38.     List1.AddItem (sServerMsg)
  39.     Socket(idxPC).Close
  40.     Unload Socket(idxPC)
  41.     cmdPC(idxPC).Enabled = False
  42.     iSockets = iSockets - 1
  43.     lblConnections.Caption = iSockets
  44. End Sub
  45.  
  46. Private Sub socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
  47. On Error GoTo err
  48.   sServerMsg = "Connection request id " & requestID & " from " & Socket(Index).RemoteHostIP
  49.  
  50.   If Index = 0 Then
  51.     'List1.AddItem (sServerMsg)
  52.     sRequestID = requestID
  53.     If err.Number = 360 Then
  54.      Socket(0).Close
  55.      Socket(0).Listen
  56.     End If
  57.     iSockets = iSockets + 1
  58.     lblConnections.Caption = iSockets
  59.     Load Socket(iSockets)
  60.     'Load Socket(Socket.UBound + 1)
  61.     Socket(iSockets).LocalPort = 1007
  62.     Socket(iSockets).Accept requestID
  63.     Label1.Caption = ""
  64.   End If
  65.  
  66.   Exit Sub
  67. err:
  68.  Socket(0).Close
  69.  Socket(0).Listen
  70.  iSockets = 0
  71.  'iSockets = iSockets - 1
  72.  Label1.Caption = CStr(err.Number) + " " + err.Description + "-" + sClientName
  73. End Sub
  74.  
  75. Private Sub socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
  76.  Socket(Index).GetData strReceived
  77.  strSplit() = Split(strReceived, "|")
  78.  sClientName = strSplit(0)
  79.  strIP = strSplit(1)
  80.  strHostName = strSplit(2)
  81.  txtClientName.Text = sClientName
  82.  txtHostName.Text = strHostName
  83.  txtIP.Text = strIP
  84.  List1.AddItem (sServerMsg + "-" + sClientName)
  85.   Select Case (sClientName)
  86.     Case "PC1"
  87.       Index = 1
  88.       cmdPC(Index).Enabled = True
  89.     Case "PC2"
  90.       Index = 2
  91.       cmdPC(Index).Enabled = True
  92.     Case "PC3"
  93.       Index = 3
  94.       cmdPC(Index).Enabled = True
  95.   End Select
  96. End Sub
  97.  
hope it will help, with simple server and 1 client there is no problem
but server and many clients kinda tricky...
Feb 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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??
2
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
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
Oralloy
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,...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.