Server是MFC的CSocket建立的Chat Server.

解决方案 »

  1.   

    Tcps.protocol=0-scktcp protocol Tcps.LocalPort = 1002 Tcps.Listen是不是协议的问题??
      

  2.   

    string轉換byte數組用函數 strconv
      

  3.   

    看一下state,是不是还是7(连接状态)
      

  4.   

    winsock_connect 得到响应。
    port应该怎么设?对方Listen的是88
    对方Client的是788。
      

  5.   

    字符和二进制都可以传的。
    如果对方listen是88,那么
    winsock1.connect 要联的IP地址,88
      

  6.   

    代码如下:
    Const HostIP = "200.121.2.110"
    Const HostPort = 788
    Const LocalPort = 788
    Const GetCommand = "Get Share Path"
    Dim sLocalPC As StringPrivate Sub cmdSend_Click()
    If txtCmd <> "" Then Call SendCmd(txtCommand.Text)
    End SubPrivate Sub Command1_Click()
    On Error GoTo errConnWith Winsock1
        If .State <> sckClosed Then .Close
        If txtServer <> "" Then .RemoteHost = txtServer
        .Connect
    End With
    Exit Sub
    errConn:
        MsgBox Err.Description
    End SubPrivate Sub Form_Load()
    Debug.Print
    Debug.Print "-----------VOD Client-------------"With Winsock1
        .Protocol = sckTCPProtocol
        .RemoteHost = HostIP        '缺省
        .RemotePort = HostPort
        '.LocalPort = LocalPort
        sLocalPC = .LocalHostName
    End With
    txtServer = HostIP
    lblPort = Str(HostPort)
    StatusBar1.Style = sbrSimple
    cmdSend.Enabled = False
    End SubPrivate Sub Form_Unload(Cancel As Integer)
       'Debug.Print "Unload frmVodClient"
       If Winsock1.State <> sckClosed Then
        Winsock1.Close
        Debug.Print "Close socket " + Str(HostPort)
       End If
    End SubPrivate Sub txtCommand_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Call SendCmd(txtCommand.Text)
    End If
    End SubPrivate Sub Winsock1_Connect()
    StatusBar1.SimpleText = "Connected"
    'With Winsock1
        '.PeekData .LocalHostName + " Joined"
        'txtShow.Text = txtShow + sLocalPC + ":Joined" + vbCrLf
        '.SendData sLocalPC + ":" + GetCommand
        'txtShow.Text = txtShow + sLocalPC + ":" + GetCommand + vbCrLf
    'End With
    cmdSend.Enabled = True
    End SubPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    'Dim i As Long
    Dim sRecv As StringDebug.Print "Data Arrival"StatusBar1.SimpleText = "Received Data"With Winsock1
        .GetData sRecv, vbString
        txtShow.Text = "Received"
    End WithEnd SubPrivate 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)
    StatusBar1.SimpleText = Str(Number) + Description
    Winsock1.Close
    End SubPrivate Sub Winsock1_SendComplete()
    StatusBar1.SimpleText = "Send Complete"
    End Sub
    Sub SendCmd(txtCmd As String)'Dim Larrfile() As ByteOn Error GoTo errSend'ReDim Larrfile(FileLen(txtCmd)) As Byte'Larrfile = txtCmdWinsock1.SendData txtCmdtxtShow.Text = txtShow + txtCmd + vbCrLfDebug.Print "SendCmd:" + txtCmdExit SuberrSend:
        MsgBox Err.Description
    End Sub
      

  7.   

    是不是代码太长了?
    其实只要拷贝下来,放到form中看就很清楚了。
      

  8.   

    定主为BYVAL就成二进制了,
    不过每次最多只能传8049  个字节
      

  9.   

    dim Byt() as byte
    redim byt(totalSize)
    winsock.getdata byt,vbbyte
      

  10.   

    当把Server关闭,就有消息返回了。
    真可笑。
      

  11.   

    是否微软的CSocket有问题?
    改用SOAP了。