1.你是往什么系统传输数据阿,是UNIX么?
2.可不可以定义一个结构依次传输1K左右的数据呢,自己做个缓冲啊。

解决方案 »

  1.   


    1。再你发送数据的时候附加结束符,自己的协议上加,在每次发送完的时候,稍微等待一会,可以很短。
    2。再Unix 端接受时要大于2k的Buffer当时我们再Unix端接受数据的时候,缓冲区小,是接受不完全的,而且如果小的可怜的话,什么都接受不到
    你发送1K 再把协议加进去,肯定大于1K了,我使用的是乘2
      

  2.   

    songyueliang(宋月亮)
      没有找到啦。
      

  3.   

    1。你要在发送的时候加一点沿时,增加自己的协议包在里面,比如开始,结束符
    2。UNIX端把接受Buffer放大点
    我当时是什么也接收不到,你幸运你还接收到了
    我改了后,在加容错处理,(VB做很弱的,建议你加上)祝你好运
      

  4.   

    songyueliang(宋月亮)
      没有找到啦。
      

  5.   

    mjs2000(宁静致远):
      延长我用了Doevents,还可以。
      现在我意识到可能和VB那个双字节有关。Uicode (拼写不知对不对)关键问题可能在这里吧。
      

  6.   

    我一搜索就失败
    这是我以前的选的一个,
    你看看好了
    不管用可别说我:)
    'Author:Dah
    'Coded time:2000.11.10  //y.m.d
    'Usage:transfer a file to another pc through intranet with winsock power
    Option Explicit
    Dim mybyte() As Byte  '发送方数组
    Const filecomesMSG = "a file is coming "  '有文件到来
    Const RemoteIsReadyMSG = "I'm ready        "  '准备好了
    Const FileisOverMSG = "the file is ended"  '文件完毕
    Const RemoteDenyMSG = "the user canceled"
    Const filecountMSG = "the file lengh is"
    Dim arrdata() As Byte  '收到的信息
    Dim filesave As Integer  '保存文件的句柄
    Dim filehandle As Integer  '发送方文件的句柄
    Dim MyLocation As Double
    Dim myMSG As String  '消息
    Dim FileisTransfer As Boolean  '文件正在传送
    Dim Isendfile As Boolean  '是否是本人在传送
    Dim FileisOver As Boolean  '文件是否已经完毕
    Dim Counttime As Integer '需要传递的次数
    Dim totaltime As Variant
    Private Sub cmdsend_Click()
    On Error GoTo errorhandle
    'this is needed for correct filename
    filehandle = FreeFile
    If Mid(File1.Path, Len(File1.Path), 1) = "\" Then
    Open File1.Path & File1.FileName For Binary Access Read As #filehandle
    Else
    Open File1.Path & "\" & File1.FileName For Binary Access Read As #filehandle
    End If
    Isendfile = True  '是本人在传送
    FileisOver = False  '文件刚开始
    cmdsend.Enabled = False
    Label1.Caption = "Wait for reply..."
    MsgBox ("the selected file size is " & LOF(filehandle) & " bytes")
    totaltime = Int(LOF(filehandle) / 4000 + 1)
    MyLocation = Loc(filehandle)
    Winsock.SendData filecomesMSG & File1.FileName    '发送发出文件信息
    Winsock.SendData filecountMSG & totaltime
    Exit Sub
    errorhandle: MsgBox ("You havn't choose a file!")
    End SubPrivate Sub Dir1_Change()
    File1.Path = Dir1.Path
    End SubPrivate Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
    End SubPrivate Sub Form_Load()
    Drive1.Drive = "c:\"
    Winsock.RemoteHost = "255.255.255.255"
    Winsock.LocalPort = 7904
    Winsock.Bind 7904
    Winsockfile.RemoteHost = "255.255.255.255"
    Winsockfile.LocalPort = 7905
    Winsockfile.Bind 7905
    FileisTransfer = False  'initialize the bool value
    Isendfile = False
    FileisOver = True
    Counttime = 0
    Label1.Caption = "Ready..."
    End SubPrivate Sub Timer1_Timer()
    Dim i As Integer
    If LOF(filehandle) - MyLocation > 4000 Then
    ReDim mybyte(0 To 4000)
    Get #filehandle, , mybyte
    MyLocation = Loc(filehandle)
    Winsockfile.SendData mybyte
    Counttime = Counttime + 1
    Label1.Caption = "the select file is being transfered..." & "about " & Counttime & " / " & totaltime
    Timer1.Enabled = False
    Else
    ReDim mybyte(0 To LOF(filehandle) - MyLocation - 1)
    Get #filehandle, , mybyte
    Winsockfile.SendData mybyte
    FileisTransfer = False
    Timer1.Enabled = False
    FileisOver = True
    End IfEnd SubPrivate Sub Winsock_DataArrival(ByVal bytesTotal As Long)
    Winsock.GetData myMSG
    Select Case Mid(myMSG, 1, 17)
    Case filecomesMSG    '这些消息发送方和接受方都可收到
    'do display a form
    If Not Isendfile Then  '接受方处理这些事情
    On Error GoTo errorhandle
    CommonDialog1.FileName = Mid(myMSG, 17, Len(myMSG))
    CommonDialog1.ShowSave
    filesave = FreeFile
    FileisTransfer = True
    cmdsend.Enabled = False
    Open CommonDialog1.FileName For Binary Access Write As #filesave
    Winsock.SendData RemoteIsReadyMSG
    Label1.Caption = "the select file is being transfered..."
    End If
    Case RemoteIsReadyMSG
    'do begin transfer a file
    '如果文件还没有结束,也就是说,只有主机才能受到
    If Isendfile Then
    If Not FileisOver Then
    Timer1.Enabled = True
    Label1.Caption = "the select file is being transfered..."
    Else
    Winsock.SendData FileisOverMSG
    End If
    End If
    Case FileisOverMSG
    If Not Isendfile Then '客户机处理
    Close #filesave
    FileisTransfer = False
    Else  '主机处理
    Isendfile = False
    Close #filehandle
    End If
    MsgBox ("the file is transfered successfully!")  '大家一起处理
    Isendfile = False
    cmdsend.Enabled = True
    Label1.Caption = "Ready..."
    Case RemoteDenyMSG
    If Isendfile Then
    MsgBox ("The user canceled this transfer session!")
    Isendfile = False
    FileisOver = True
    cmdsend.Enabled = True
    Label1.Caption = "Ready..."
    Close #filehandle
    End If
    Case filecountMSG
    If Not Isendfile Then
    totaltime = Mid(myMSG, 17, Len(myMSG))
    End If
    End Select
    Exit Sub
    errorhandle: Winsock.SendData RemoteDenyMSG
    End Sub
    Private Sub writetofile()
    Put #filesave, , arrdata
    End SubPrivate Sub Winsockfile_DataArrival(ByVal bytesTotal As Long)
    If FileisTransfer Then
    Winsockfile.GetData arrdata, vbArray + vbByte, 4001
    writetofile
    Winsock.SendData RemoteIsReadyMSG
    Counttime = Counttime + 1
    Label1.Caption = "the select file is being transfered..." & "about " & Counttime & "/" & totaltime
    End If
    End Sub
      

  7.   

    给你一个模块是我曾经用过的从Windows系统和Unix系统传输数据的时候做的,VB的数据要发往UNIX系统下面一定要转换成BYTE的。
    Public Function All2Byte(ByVal vData As Variant, vByte() As Byte, ByVal vType As Integer, Optional vStart As Integer, Optional ByVal vLen As Integer) As Integer
        Dim i As Integer
        Dim j As Integer
        Dim tmpInt As Integer
        Dim tmpLng As Long
        Dim tmpStr As String
        Dim tmpChr As String
        
        i = 1
        j = 1
        Select Case vType
            Case vbInteger
                tmpInt = CInt(vData)
                tmpStr = Hex(tmpInt)
                If Len(tmpStr) < 4 Then
                    For i = 1 To 4 - Len(tmpStr)
                        tmpStr = "0" + tmpStr
                    Next
                End If
                For i = 2 To 1 Step -1
                    tmpChr = Mid(tmpStr, (i - 1) * 2 + 1, 2)
                    tmpChr = "&H" + tmpChr
                    vByte(vStart + j - 1) = CByte(tmpChr)
                    j = j + 1
                Next
            Case vbLong
                tmpLng = CLng(vData)
                tmpStr = Hex(tmpLng)
                If Len(tmpStr) < 8 Then
                    For i = 1 To 8 - Len(tmpStr)
                        tmpStr = "0" + tmpStr
                    Next
                End If
                For i = 4 To 1 Step -1
                    tmpChr = Mid(tmpStr, (i - 1) * 2 + 1, 2)
                    tmpChr = "&H" + tmpChr
                    vByte(vStart + j - 1) = CByte(tmpChr)
                    j = j + 1
                Next
            Case vbDouble
                tmpLng = CLng(vData)
                tmpStr = Hex(tmpLng)
                If Len(tmpStr) < 16 Then
                    For i = 1 To 16 - Len(tmpStr)
                        tmpStr = "0" + tmpStr
                    Next
                End If
                For i = 8 To 1 Step -1
                    tmpChr = Mid(tmpStr, (i - 1) * 2 + 1, 2)
                    tmpChr = "&H" + tmpChr
                    vByte(vStart + j - 1) = CByte(tmpChr)
                    j = j + 1
                Next
            Case vbString '还缺少中文的处理情况
                For j = 1 To vLen
                    vByte(vStart + j - 1) = Asc(Mid(vData, j, 1))
                Next
            Case Else
                All2Byte = 1
        End Select
        All2Byte = 0
    End Function