Results 1 to 12 of 12

Thread: socket help in vb.net 2008

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    14

    socket help in vb.net 2008

    Hello,
    I have been trying sometime now to just figure out how to make a UDP connection with VB.NET 2008 and can't seem to figure it out. I even found 4 books on VB.NET but don't mention a thing about sockets but talk about web based stuff. I defitaly need to use a UDP socket. In VB6.0 this was easy. I have search the internet and fourms and put some code together to send hello world. But I can't seem to get it to work... The receiving side is a Linux computer which can receive data sent from itself on 127.0.0.1.

    If someone could give me some insite i would really appricate it.
    thanks

    Code:
    Imports System.Net.Sockets
    Imports System.Text
    Public Class Form1
        Dim clientSocket As New UdpClient
    
        Private Sub ConnectButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConnectButton.Click
    
        End Sub
    
        Private Sub GoLeftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoLeftButton.Click
            Dim bytCommand As Byte() = New Byte() {}
    
            clientSocket.Connect(IPTxt.Text, PortTxt.Text)
            bytCommand = Encoding.ASCII.GetBytes("hello world")
            clientSocket.Send(bytCommand, bytCommand.Length)
    
    
        End Sub
    End Class

  2. #2
    Member
    Join Date
    Jun 2009
    Posts
    53

    Re: socket help in vb.net 2008

    im presuming that this is the client's code. im not exactly sure why it isnt working so can you please elaborate? what are you using to program the linux computer? search for "udp" on msdn.com for more help and even an example. also change this:
    Code:
    clientSocket.Connect(IPTxt.Text, PortTxt.Text)
    to this:
    Code:
    clientSocket.Connect(IPTxt.Text, CInt(PortTxt.Text))
    since the port parameter you were giving it was a string not an integer

  3. #3
    Hyperactive Member Monkz's Avatar
    Join Date
    Aug 2009
    Posts
    304

    Re: socket help in vb.net 2008

    I am trying to make a similar program, but am new to VB.net 2008. Would u be able to show me the code of the recieving program which i could use as a reference?

  4. #4
    Junior Member
    Join Date
    Aug 2009
    Location
    Australia, Melbourne
    Posts
    29

    Re: socket help in vb.net 2008

    Take a look at this example/demo: TinyUDP

    Very good and object oriented approach at a simple UDP client/server application. Have a look over that and study it

  5. #5
    Hyperactive Member Monkz's Avatar
    Join Date
    Aug 2009
    Posts
    304

    Re: socket help in vb.net 2008

    It is in a lower version of VB.Net tho

  6. #6
    Junior Member
    Join Date
    Aug 2009
    Location
    Australia, Melbourne
    Posts
    29

    Re: socket help in vb.net 2008

    It doesn't matter. The Visual Studio Conversion Wizard converts it perfectly fine for me and it compiles and executes without an issue. I am using Visual Studio 2008 but 2005 should be fine. But if you would like to learn more a better way is to write/copy it yourself into your own project, because as you write you learn and understand stuff you might not see when you just look over it or convert it.

  7. #7
    Hyperactive Member Monkz's Avatar
    Join Date
    Aug 2009
    Posts
    304

    Re: socket help in vb.net 2008

    I tried doing that, but i just dont get it :S

  8. #8
    Junior Member
    Join Date
    Aug 2009
    Location
    Australia, Melbourne
    Posts
    29

    Re: socket help in vb.net 2008

    You don't get how to use it? or it doesn't come up?

    If it doesn't come up the project is fine but if it DOES show up then just click...

    1. Click NEXT
    2. Then tell it you dont want to make a backup (NO) then NEXT again
    3. Then click FINISH
    4. Then click CLOSE

  9. #9
    Hyperactive Member Monkz's Avatar
    Join Date
    Aug 2009
    Posts
    304

    Re: socket help in vb.net 2008

    I converted it fine, but i just dont get alot of it..

    Why is it separated between Tiny UDP and TinyUDP_Test, and what is the reasoning for the code to be split like that...

    Also what is the thing that they are Importing? :S

  10. #10
    Hyperactive Member Monkz's Avatar
    Join Date
    Aug 2009
    Posts
    304

    Re: socket help in vb.net 2008

    I have a project going, tho its done noticeably different.. I have the client sending the packet.. Im just having issues with the server recieving.. Would u possibly be able to help me through a couple of my errors?

  11. #11
    Junior Member
    Join Date
    Aug 2009
    Location
    Australia, Melbourne
    Posts
    29

    Re: socket help in vb.net 2008

    Its split into 2 projects...

    First is the DLL which is the actual classes (TinyServer and TinyClient).

    The second project is a windows form project that uses the functions in the DLL.

    Its a OOP approach which is the more favorable way to do things in a programming sense when applicable. Its good because you can reuse the code instead of having to write out the functions all again if you need them you just have to import the Tiny.UDP namespace(DLL) and then just create and object of the appropriate class and call the functions/methods.

    Please attach your project if you can and ill take a look at it, don't include any executable format files though as there not allowed.

  12. #12
    Hyperactive Member Monkz's Avatar
    Join Date
    Aug 2009
    Posts
    304

    Re: socket help in vb.net 2008

    Here it is.
    Attached Files Attached Files

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