Home All Groups Group Topic Archive Search About

how to receive data from .NET socket into VB6 winsock ?

Author
7 Sep 2006 10:09 AM
cadriansyah
i have a socket apllication written in .NET (VB) that send data
(microsoft sample)

    Public Sub SendData(ByVal Data As String)
        ' Synclock ensure that no other threads try to use the stream
at the same time.
        SyncLock client.GetStream
            Dim writer As New IO.StreamWriter(client.GetStream)
            writer.Write(Data & Chr(13) & Chr(10))

            ' Make sure all data is sent now.
            writer.Flush()
        End SyncLock
    End Sub
.....
.....
client.SendData(strMessage)
.....
.....
#  but when i receive from vb6 application #

Public Sub sockMain_DataArrival(ByVal bytesTotal As Long)

    Dim strData As Variant
    MDIForm1.sockMain.GetData strData

    If Not IsNull(strData) Then
        MsgBox strData
    End If

End Sub

it returns NUMBER (numerical value)
what does it mean ?
how do i translate it ?

how do i find an equivalent function as thi one :
strMessage = Encoding.ASCII.GetString(readBuffer, 0, BytesRead - 2)

thank you

Author
7 Sep 2006 12:07 PM
Truong Hong Thi
I suggest you try like this:
When sending:
Dim writer As New IO.StreamWriter(client.GetStream, Encoding.ASCII)

When receiving:
Dim strData As String
MDIForm1.sockMain.GetData strData, vbString

cadrians***@gmail.com wrote:
Show quoteHide quote
> i have a socket apllication written in .NET (VB) that send data
> (microsoft sample)
>
>     Public Sub SendData(ByVal Data As String)
>         ' Synclock ensure that no other threads try to use the stream
> at the same time.
>         SyncLock client.GetStream
>             Dim writer As New IO.StreamWriter(client.GetStream)
>             writer.Write(Data & Chr(13) & Chr(10))
>
>             ' Make sure all data is sent now.
>             writer.Flush()
>         End SyncLock
>     End Sub
> ....
> ....
> client.SendData(strMessage)
> ....
> ....
> #  but when i receive from vb6 application #
>
> Public Sub sockMain_DataArrival(ByVal bytesTotal As Long)
>
>     Dim strData As Variant
>     MDIForm1.sockMain.GetData strData
>
>     If Not IsNull(strData) Then
>         MsgBox strData
>     End If
>
> End Sub
>
> it returns NUMBER (numerical value)
> what does it mean ?
> how do i translate it ?
>
> how do i find an equivalent function as thi one :
> strMessage = Encoding.ASCII.GetString(readBuffer, 0, BytesRead - 2)
>
> thank you
Author
8 Sep 2006 6:17 AM
SuperSentaiCollection
it works !

thank you very much.


Truong Hong Thi wrote:
Show quoteHide quote
> I suggest you try like this:
> When sending:
> Dim writer As New IO.StreamWriter(client.GetStream, Encoding.ASCII)
>
> When receiving:
> Dim strData As String
> MDIForm1.sockMain.GetData strData, vbString
>
> cadrians***@gmail.com wrote:
> > i have a socket apllication written in .NET (VB) that send data
> > (microsoft sample)
> >
> >     Public Sub SendData(ByVal Data As String)
> >         ' Synclock ensure that no other threads try to use the stream
> > at the same time.
> >         SyncLock client.GetStream
> >             Dim writer As New IO.StreamWriter(client.GetStream)
> >             writer.Write(Data & Chr(13) & Chr(10))
> >
> >             ' Make sure all data is sent now.
> >             writer.Flush()
> >         End SyncLock
> >     End Sub
> > ....
> > ....
> > client.SendData(strMessage)
> > ....
> > ....
> > #  but when i receive from vb6 application #
> >
> > Public Sub sockMain_DataArrival(ByVal bytesTotal As Long)
> >
> >     Dim strData As Variant
> >     MDIForm1.sockMain.GetData strData
> >
> >     If Not IsNull(strData) Then
> >         MsgBox strData
> >     End If
> >
> > End Sub
> >
> > it returns NUMBER (numerical value)
> > what does it mean ?
> > how do i translate it ?
> >
> > how do i find an equivalent function as thi one :
> > strMessage = Encoding.ASCII.GetString(readBuffer, 0, BytesRead - 2)
> >
> > thank you