最后40分~!怎样用winsock控件传输,字符数组!!谢谢拉~急啊~!

adisen 2004-12-26 08:24:19
最后40分~!怎样用winsock控件传输,字符数组!!谢谢拉~

dim f(200) as string

我应该怎样用wiosock发送和接受呢~

谢谢~~
...全文
62 点赞 收藏 3
写回复
3 条回复
itcoco 2004年12月26日
发送的时候,直接
dim str() as string
If winsock1.State = sckConnected Then
.SendData str
ElseIf .State <> sckConnected Then
.Close
.Connect pub_Str_ServerIp, pub_Str_ServerPort
End If
接收的时候直接按字符串接收就可以了吧:
dim strData as string
Winsock1 .GetData strData
回复 点赞
zyg0 2004年12月26日
Option Explicit


Dim b(1, 1) As String
Private Sub Form_Load()
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 1001
b(0, 0) = "a": b(1, 1) = "c"
b(1, 0) = "b": b(0, 1) = "d"
End Sub
Private Sub Command1_Click()
Winsock1.SendData setArr(b)
End Sub
'传送时的函数
Public Function setArr(a() As String) As String
Dim temp As String
Dim i, j As Integer
For i = 0 To 1
For j = 0 To 1
temp = temp & a(i, j) & "(_)()_&"
Next
temp = temp & "#!@$!!#$$^&%%^"
Next
setArr = temp
End Function



'接收端:
Option Explicit
Dim cl(1, 1) As String

Private Sub Form_Load()
Winsock1.LocalPort = 1001
Winsock1.Bind
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim b() As String
Dim c() As String
Dim i As Integer
Dim j As Integer
Dim st As String
Winsock1.GetData st, vbString
b = GetArrFill(st)
For i = 0 To UBound(b) - 1
c = GetArr(b(i))
For j = 0 To UBound(c) - 1
Text1.Text = Text1 & c(j) & " "
cl(i, j) = c(j)
Next
Next

End Sub
'接受时的函数
Public Function GetArr(a As String) As String()
Dim temp() As String
temp = Split(a, "(_)()_&")
GetArr = temp
End Function
Public Function GetArrFill(a As String) As String()
Dim temp() As String
temp = Split(a, "#!@$!!#$$^&%%^")
GetArrFill = temp
End Function
回复 点赞
dongle2001 2004年12月26日
Private Sub TCP1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim vta
Dim bt() As String
TCP1(Index).GetData vta, vbArray + vbString
bt = vta
...
End Sub
回复 点赞
发动态
发帖子
网络编程
创建于2007-09-28

1145

社区成员

1.8w+

社区内容

VB 网络编程
社区公告
暂无公告