none
Can Visual Studio 2010 use winsock 6.0 for programming ??? RRS feed

  • 问题

  • In The VS2010 ,VB.NET,I  use Winsock 6.0 can send some data,but getdata meet  some mistakes。

         AxWinsock1.GetData(data) ;data as Object ???? What's wrong ???

    detailed:Look at the code next:

    Code:

    Imports AxMSWinsockLib

    Public Class Form1

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            AxWinsock1._RemoteHost = "127.0.0.1"
            AxWinsock1.LocalPort = 2000
            AxWinsock1.RemotePort = 2000
            AxWinsock1.Bind()

        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            AxWinsock1.SendData(TextBox1.Text)
        End Sub

        Private Sub AxWinsock1_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles AxWinsock1.DataArrival
            Dim data
            AxWinsock1.GetData(data)
        End Sub
    End Class

          
    2014年10月18日 6:48

答案

  • 你好,

    >> AxWinsock1.GetData(data) ;data as Object ???? What's wrong ???

    对于这个问题,建议你看这篇文档:http://msdn.microsoft.com/en-us/library/aa228098%28VS.60%29.aspx

    以下是VB.net 中的写法, 使用了UBound 方法去获取数组最大下标:

    Private Sub AxWinsock1_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles AxWinsock1.DataArrival
            'MessageBox.Show("data arrived")
    
            Dim strData As Object
            Dim i As Integer
            Dim tstring As String
            tstring = ""
    
            AxWinsock1.GetData(strData)
    
            For i = 0 To UBound(strData)
                tstring = tstring + Chr(strData(i))
            Next
    
            TextBox1.Text = tstring
    
        End Sub

    项目代码: http://1drv.ms/1yQw8Jx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年10月20日 3:25
    版主