我现用WINSOCK做“从客户端单向发送数据到服务端”,现存在断点续传的问题。客户端因某种原因(网络、程序中断)需重启程序后,不能自动再连接发数。我将WINSOCK重新关闭(CLOSE),再重新设定服务器端口和IP地址,都不行,状态一直为6,也延时了900毫秒。客户端就是不能再重新连接发数。而服务端断开再连接可以做到。
  怎样让客户端在断开后,继续连接发送?急死了!请帮帮我吧!

解决方案 »

  1.   

    tcp连接是双边的事情,要两边都同意才能完成一件事情
      

  2.   

    诸位仙人:正常情况下,我已经完成了单向发送。现在主要解决客户端的WINSOCK状态为6时,如何让它为7。在为6时,服务方的端口、IP地址,我都重新设定了,且WINSOCK.close。但无济于事。测试代码如下:
    Private Sub Form_Load()
    '打开数据库
    'Text1.Text = ""
    'Text2.Text = ""
    'Text3.Text = ""
    'Text4.Text = ""
      Set cn = New ADODB.Connection
      strcn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & paths & "meter.mdb;Persist Security Info=false"
      cn.ConnectionString = strcn
      cn.Open
      
      
      
    Winsock1.RemoteHost = "172.16.66.158"  '以后要改为B机的IP地址
    Winsock1.RemotePort = 2000
    Winsock1.Connect                      '连接B机
    Label4.Caption = "第0次:" + Str(Winsock1.State)End Sub
    Private Sub Form_Unload(Cancel As Integer)
    Winsock1.Close
    End SubPrivate Sub Timer1_Timer()
    If Second(Time) > 0 Then
        Exit Sub
      End If
    'Winsock1.RemoteHost = "172.16.66.158"  '以后要改为B机的IP地址
    'Winsock1.RemotePort = 2000
    If Winsock1.State <> 7 Then
    Label4.Caption = "<>7重连一次:" + Str(Winsock1.State)
    Winsock1.CloseWinsock1.RemoteHost = "172.16.66.158"  '以后要改为B机的IP地址
    Winsock1.RemotePort = 2000
    Winsock1.Connect
    End If
    '连接B机
    Label4.Caption = "第一次:" + Str(Winsock1.State)With cmd
        .ActiveConnection = cn
        .CommandType = adCmdText
        .CommandText = "select * from tabsend where 上传='N'"
      End With
      
       Set rsshow = New ADODB.Recordset
      With rsshow
       .CursorLocation = adUseClient
       .CursorType = adOpenDynamic
       .LockType = adLockOptimistic
       .Open cmd
       If Not (.BOF And .EOF) Then
         .MoveLast
         Set dgmeter.DataSource = rsshow    a = dgmeter.Columns(0) 'Text1.Text
        b = dgmeter.Columns(1) 'Text2.Text
        c = dgmeter.Columns(2) 'Text3.Text
        d = dgmeter.Columns(3) 'Text4.Text
        sendstr = a + "*" + b + "%" + c + "$" + d
        Label2.Caption = sendstr
        Label3.Caption = ""
        Label3.Caption = "发之前的状态:" + Str(Winsock1.State)
        'Winsock1.Close
       If Winsock1.State <> 7 Then
    Label4.Caption = "第二次uqw 连:" + Str(Winsock1.State)
    Winsock1.CloseWinsock1.RemoteHost = "172.16.66.158"  '以后要改为B机的IP地址
    Winsock1.RemotePort = 2000
    Winsock1.Connect
    Label6.Caption = "最后连:" + Str(Winsock1.State)
    End If
    Label7.Caption = "最后jjjjjjj连:" + Str(Winsock1.State)
     If Winsock1.State = 7 Then
     Label5.Caption = "=7现在就发的状态" + Str(Winsock1.State)
       'A机对外发送
        Winsock1.SendData sendstr
        rsshow!上传 = "Y"
        rsshow.Update
        End If
      End If
     End With
     delayTime = Timer + 1
        Do While delayTime > Timer
          DoEvents
        Loop
         rsshow.Close
    End SubPrivate Sub Winsock1_Close()
    Winsock1.Close
    End Sub