Click here to Skip to main content
13,201,763 members (74,091 online)

Sending 3 bytes message in UDP

MadeByVince asked:

Open original thread
Hi all,

I'm trying to do a small application that can simply send a 3 bytes message in UDP to a specified IP address but I cannot make it work.
All I want seems really simple, just a small interface with one textbox to specify the destination IP address and one single button to send a 3 bytes message like "0x01 0x25 0xFA" in a single packet to the IP specified in the textbox and using a fixed port specified directly in the code.
This look so simple, and is probably very simple, but... ;o)
I tried to use the udpClient.Send command but it seems I don't really understand how to use it.
Can you help me ?

Many thanks

Vince

<Moved from Solution 1 to question>

Hi,
OK, I agree my information are a little bit short ;o)
So, first of all, I'm a newbee in "modern" developpment. I made a lot of things 10 or 15 years ago but only very simple things since that time.
Here is my non working code I made after checking weveral websites and examples (please don't laugh ;o) )
Public Class Form1
Inherits System.Windows.Forms.Form
Dim DestinationIP As IPAddress
Dim bytCommand As Byte() = New Byte() {}
Dim udpClient As New UdpClient

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim pRet As Integer

DestinationIP = IPAddress.Parse(DestIP.Text)
udpClient.Connect(DestinationIP, 10242)
pRet = udpClient.Send("0x01 0x25 0xFA", 3)
Console.WriteLine("No of bytes send " & pRet)

End Sub
End Class



I always get errors on the udpClient.Send line. On the code above the error is "Value of type 'String' cannot be converted to '1-dimentional array of byte'.

Thx
Tags: C++, C#, VB, VB.NET, Windows (Win7)

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy |
Web04 | 2.8.171020.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100