broadcast packet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deeas
    New Member
    • Feb 2009
    • 18

    broadcast packet

    hi everyone :
    please how to change the destination address from "localhost" to the ip: "192.168.1. 1"
    Code:
    Static port_server As Integer = 5000
    Static name_server As String = "localhost"
    Static port_client As Integer = 5001
    
    Dim sock_server As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
    sock_server.EnableBroadcast = True
    Dim serverEP As IPEndPoint = New IPEndPoint(Dns.GetHostEntry(name_server).AddressList(0), port_server)
    Dim clientEP As IPEndPoint = New IPEndPoint(Dns.GetHostEntry(name_server).AddressList(0), port_client)
    Dim enter_string As String = "hello"
    Dim send_byte() As Byte
    send_byte = System.Text.Encoding.ASCII.GetBytes(enter_string)
    sock_server.Bind(clientEP)
    sock_server.SendTo(send_byte, SocketFlags.None, serverEP)
    and how to send broadcast packet.
    Last edited by Frinavale; Mar 2 '09, 07:59 PM. Reason: Added [code] tags: Please post code in [code] [/code] tags
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Change:
    Dim serverEP As IPEndPoint = New IPEndPoint(Dns. GetHostEntry(na me_server).Addr essList(0), port_server)
    to
    Dim serverEP As IPEndPoint = New IPEndPoint(Dns. GetHostEntry("1 92.168.1.1").Ad dressList(0), port_server)

    However its not really a broadcast packet if you are sending it to one device. I think you need to reasearch what you reall want to do first and then decide what is right.

    Comment

    • deeas
      New Member
      • Feb 2009
      • 18

      #3
      my question consists of tow parts , how to change the destination and how to send broadcast.
      i wait answer for the second part

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well now my answer has two parts.
        One is to change the server ip to the ip of where you want to send the message to.
        The other part is to look up your questions before posting them:

        Comment

        • deeas
          New Member
          • Feb 2009
          • 18

          #5
          at first thanks for reply .
          i tried alot of codes in vb and c# but i had problem at receiver so i thought that maybe there is some thing wrong.
          sorry for annoying.

          Comment

          • deeas
            New Member
            • Feb 2009
            • 18

            #6
            good evening
            please i'm trying my programs in VMware workstation, there is webserver in localhost send broadcast message and wait for responses, there is
            java program running on every host , but the server couldn't receive from any one except localhost i hope you understand me and i wait your help.


            Dim iep As IPEndPoint = New IPEndPoint(IPAd dress.Broadcast , 5001)
            Dim Remote As EndPoint = CType(iep, EndPoint)
            ' sock_server.Bin d(iep)
            Dim byte_recieve(25 6) As Byte
            sock_server.Rec eiveFrom(byte_r ecieve, SocketFlags.Non e, Remote)

            Dim server_text As String = System.Text.Enc oding.ASCII.Get String(byte_rec ieve)
            TextBox2.Text = server_text

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Broadcast messages aren't routed, so you all need to be on the same network for that to work

              Comment

              Working...