Results 1 to 7 of 7

Thread: Sending Data from vb.Net to VB 6.0 winsock

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    3

    Sending Data from vb.Net to VB 6.0 winsock

    Hi

    I have an application in VB 6.0 which acts as a server.. I have an application in .Net (for smart devices) which will act as a client..

    Now I need to send data from the client to the server..

    Is this possible?

    I use winsock in VB 6.0 and Socket class in VB .Net

    Please help me with this...

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Sending Data from vb.Net to VB 6.0 winsock

    Yes, it is possible. Any basic .NET sockets tutorial will teach you how to establish a connection from a client.

    A TCP (or UDP, whatever you're using) connection, is still a TCP connection regardless of what programming language you're using.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Sending Data from vb.Net to VB 6.0 winsock

    It seems like you might get some slightly unexpected behavior if you are sending strings, though, since .NET defaults to Unicode, which is two bytes per character, while VB6 was ASCII with one byte per character. That's just a matter of making sure both sides are speaking the same language, but it should only be an issue if you are doing certain types of things.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    3

    Re: Sending Data from vb.Net to VB 6.0 winsock

    Thanks for the response Guys.. I have already tried, but its not working... Will get the code and put it up here...

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Sending Data from vb.Net to VB 6.0 winsock

    In addition to the code, please post the exact wording of any error messages that you are getting, and what line of code is causing the error.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    3

    Re: Sending Data from vb.Net to VB 6.0 winsock

    This is my VB.Net code... I need to run this on Windows mobile 5.0 emulator as I will be using a PDA to communicate with the PC...

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim addr As IPAddress
            Dim port As Integer
            Dim client As New TcpClient
            addr = IPAddress.Parse("192.168.0.20")
            port = 10020
            Dim endpoint As New IPEndPoint(addr, port)
            Dim s As New Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
            s.Connect(endpoint)
            If s.Connected Then
                MsgBox("Connected")
            End If
            Dim networkStream As NetworkStream = client.GetStream()
            Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("1")
            networkStream.Write(sendBytes, 0, sendBytes.Length)
            MsgBox("connection set")
        End Sub
    Following is the server code that will be on the PC:

    Code:
    Private Sub Form_Load()
    Winsock1.Listen
    End Sub
    
    
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Winsock1.Close
    Winsock1.LocalPort = 10020
    Winsock1.Accept requestID
    End Sub
    
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Winsock1.GetData dt
    If dt = "1" Then
      Call Right
    End If
    End Sub

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Sending Data from vb.Net to VB 6.0 winsock

    You are creating a new socket, to communicate with 192.168.0.20...
    But you are trying to write to the TcpClient's NetworkStream, even though you havent connected the TcpClient to anything yet.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width