本文介绍了在UDP中发送3字节消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我正在尝试做一个小应用程序,只需将UDP中的3字节消息发送到指定的IP地址,但我不能让它起作用。 我想要的只是一个非常简单的东西,只是一个带有一个文本框的小接口,用于指定目标IP地址,一个按钮用于将单个数据包中的0x01 0x25 0xFA等3字节消息发送到在文本框中指定IP并使用代码中直接指定的固定端口。 这看起来很简单,可能很简单,但是......; o) 我尝试使用udpClient.Send命令,但似乎我真的不明白如何使用它。 你能帮助我吗? 非常感谢 Vince <从解决方案1移至问题> 好的,我同意我的信息有点短; o) 所以,首先,我是现代发展的新手。我在10年或15年前制作了很多东西但是从那时起只做了很简单的事情。 这是我在检查了几个网站和例子后做的非工作代码(请不要笑; o)) 公共 类 Form1 继承 System.Windows.Forms.Form Dim DestinationIP As IPAddress Dim bytCommand As 字节()= 新 字节(){} Dim udpClient 作为 新 UdpClient 私有 Sub Button1_Click(发件人为 对象,e As EventArgs)句柄 Button1.Click Dim pRet As Integer DestinationIP = IPAddress.Parse(DestIP.Text) udpClient.Connect(DestinationIP, 10242 ) pRet = udpClient.Send( 0x01 0x25 0xFA, 3 ) Console.WriteLine( 没有字节发送 &安培; pRet) 结束 Sub 结束 类 我总是在udpClient.Send行上出错。在上面的代码中,错误是类型的值''字符串''不能转换为''1维数组的字节''。 Thx 解决方案 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 thanksVince<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 Form1Inherits System.Windows.Forms.FormDim DestinationIP As IPAddressDim bytCommand As Byte() = New Byte() {}Dim udpClient As New UdpClientPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickDim pRet As IntegerDestinationIP = IPAddress.Parse(DestIP.Text)udpClient.Connect(DestinationIP, 10242)pRet = udpClient.Send("0x01 0x25 0xFA", 3)Console.WriteLine("No of bytes send " & pRet)End SubEnd 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 解决方案 这篇关于在UDP中发送3字节消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!