|
-
Mar 12th, 2005, 11:18 AM
#1
Thread Starter
Addicted Member
Send listbox content via winsock ???
Hi,
How can i send the content of list1 with winsock to
list2 ?
thx !
-
Mar 12th, 2005, 02:18 PM
#2
Re: Send listbox content via winsock ???
 Originally Posted by Tha Joey Madnez
Hi,
How can i send the content of list1 with winsock to
list2 ?
thx ! 
are these seperate apps or are the listboxes on the same form?
Pino
-
Mar 12th, 2005, 02:39 PM
#3
Thread Starter
Addicted Member
Re: Send listbox content via winsock ???
A client and server
-
Mar 12th, 2005, 03:58 PM
#4
-
Mar 12th, 2005, 04:27 PM
#5
Thread Starter
Addicted Member
Re: Send listbox content via winsock ???
Got any code ?
-
Mar 12th, 2005, 05:58 PM
#6
Re: Send listbox content via winsock ???
Kinda like this. Haven't tested it but it's the general idea :
VB Code:
'Send code
Dim i As Integer
Dim strSend As String
Dim sDelimiter As String
sDelimiter = "+++"
For i = 0 To List1.ListCount - 1
strSend = strSend & List1.List(i) & sDelimiter
Next
strSend = Left(strSend, Len(strSend) - Len(sDelimiter))
'After here, you send
And
VB Code:
'Recieve code
Dim i As Integer
Dim strData As String
Dim sDelimiter As String
Dim Ar() As String
sDelimiter = "+++"
Ar = Split(strData, sDelimiter)
For i = 0 To UBound(Ar)
List2.AddItem Ar(i)
Next
The only problem is that if an item in the listbox has +++ in it, the splitting won't work right
Has someone helped you? Then you can Rate their helpful post. 
-
Mar 13th, 2005, 06:20 AM
#7
Member
Re: Send listbox content via winsock ???
This is the idea but it doesn't really work as the data is send to fast just appears as one string, ways around it though.
server,
VB Code:
Option Explicit
Private Sub Form_Load()
With Winsock1
.LocalPort = 9999
.Listen
End With
Form1.Show
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim dat As String
Winsock1.GetData dat
List1.AddItem dat
End Sub
client,
VB Code:
Option Explicit
Private i As Long
Private Sub Command1_Click()
For i = 0 To List1.ListCount - 1
Winsock1.SendData List1.List(i)
DoEvents
DoEvents
Next i
End Sub
Private Sub Form_Load()
Winsock1.Connect "localhost", 9999
For i = 0 To 10
List1.AddItem "test" & i
Next i
End Sub
-
Mar 13th, 2005, 06:21 AM
#8
Thread Starter
Addicted Member
Re: Send listbox content via winsock ???
ThX !
-
Mar 13th, 2005, 06:30 AM
#9
Member
Re: Send listbox content via winsock ???
Here's a way of creating a delay, bit long winded though,
server,
VB Code:
Option Explicit
Private Sub Form_Load()
With Winsock1
.LocalPort = 9999
.Listen
End With
Form1.Show
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim dat As String
Winsock1.GetData dat
List1.AddItem dat
Winsock1.SendData "NEXT"
End Sub
client,
VB Code:
Option Explicit
Private i As Long
Private j As Long
Private Sub Command1_Click()
If j > List1.ListCount Then
Winsock1.Close
End If
Winsock1.SendData List1.List(j)
j = j + 1
End Sub
Private Sub Form_Load()
Winsock1.Connect "localhost", 9999
For i = 0 To 10
List1.AddItem "test" & i
Next i
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim dat As String
Winsock1.GetData dat
If dat = "NEXT" Then
Command1_Click
End If
End Sub
-
Mar 13th, 2005, 06:35 AM
#10
Member
Re: Send listbox content via winsock ???
You'll find though that when your sending data over the internet there will be a delay anyway due to the distance, well depening on the conection speeds, so my first method would probably work fine in that case. Second method is fullproof though.
-
Mar 13th, 2005, 12:31 PM
#11
Re: Send listbox content via winsock ???
why not use packet delimeters? theres a link in my sig 

Pino
-
Mar 14th, 2005, 11:23 PM
#12
Member
Re: Send listbox content via winsock ???
If your app is going to do more then send packets containing the list content i suggest when you send your list content you add a header "LIST" or something like that in the beginning of the packet so you can check and process each packet the way it needs. Use chr(13) as a delimeter.
Kiss, Aerosmith, Black Sabbath, Nazareth, Judas Priest, Status Quo, Cinderella, Scorpions, Tool, SteppenWolf.
-
Mar 15th, 2005, 03:49 AM
#13
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|