完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
你好,所以我想用UDP/IP协议从服务器发送数据到UC,我没有经验,但是我最近尝试挖掘,我想到的第一个问题是服务器可以向客户发送数据(PIC32在我的情况下),而不需要这个客户机首先要求建立连接。在?第二个问题是要从服务器端打开一个套接字,我需要LocalAdvor和LocalPoT(如在文件UTP.C中的TCP/IP堆栈中的函数打开套接字中提到的),所以这些本地信息是针对服务器的,即客户端的IP地址和本地地址。GHTS给了我一些开始编程的想法。我使用MPLAB X和V2.02和XC32编译器,我尝试用C++编写代码。
以上来自于百度翻译 以下为原文 Hello, So I want to send data from server to uC using UDP/IP protocole I have no experience with that but I am trying to dig lately and the first question that came to my mind is can a server send data to a client (PIC32 in my case ) without being first asked by this same client to establish connexion ? Second question to open a socket from the server side I need localAddress and localPort ( as mentioned in the function opening socket in the TCP/IP stack in file udp.c ) so these local informations are for the server the client's IP address and local address I suppose. I wish you can clarify my thoughts and give me some idea to start programming. I am using Mplab x with hARMony V2.02 and xc32 compiler and I am trying to code in C++. Best regards |
|
相关推荐
19个回答
|
|
|
|
|
|
|
|
|
在HythFoLDAPAP>& TcPIP≫& TcPIpU.UppClututu中,可以使用第三方应用程序在TCP或UDP套接字上发送数据,例如“HelCules安装”(谷歌IT)。
以上来自于百度翻译 以下为原文 check example in harmony folder app>>tcpip>>tcpip_udp_client u can use third party applications to send data over tcp or udp socket.. Like 'Hercules Setup' (google it) |
|
|
|
|
|
谢谢你的回复,但是你能回答我的问题吗?因为我已经看到了代码,但是TIGNS在我的脑子里乱七八糟。
以上来自于百度翻译 以下为原文 Thanks for your reply but can you respond to my questions cause I already saw that code but thnigs are messy in my head |
|
|
|
|
|
因此,我再次询问是否有人能帮助我理解,现在我创建了2个类:UDPclipse和UDPserver。在第一个类中,我打开了一个套接字,在这个套接字中放置了一个远程端口和IP地址(服务器),并且我将发送一个“发送”函数,将数据(UDP帧)发送到服务器,然后服务器返回。艾夫斯通过发送数据将这些数据和应答(在UDDServer类中实现的函数发送和接收)返回到客户端。我的问题是当调用Debug函数(UDPServer类)时,我需要一些软件来让服务器向客户端发送帧,或者我可以在代码中定义数据。并将其作为参数发送到“发送”函数中?我希望我已经清楚了,谢谢!
以上来自于百度翻译 以下为原文 So I am asking once again if someone can help me understand, now I created 2 classes : udpClient and udpServer. In the first class I open a socket where I put a remote port and IP address (of the server) and I put a "send" function that will send data ( UDP frames) to the server then the server receives these datas and replies ( function send and receive implemented in the udpServer class) back to the client by sending data. My question is when calling send function (of the udpServer class) do I need some software to let the server send frames to the client or I can just define data in my code and pass it as a parameter inside "send" function ? I hope that I have been clear, Thank you ! |
|
|
|
|
|
我会说“是的”,虽然我没有在图片上使用C++,甚至没有和谐。你能编一些代码并张贴在这里吗?
以上来自于百度翻译 以下为原文 I'd say "yes", though I've not used C++ on PICs and not even Harmony. Can you make up some code and post it here? |
|
|
|
|
|
谢谢你的回复,你会同意使用软件从服务器发送数据吗?对于代码,我将尝试编写一些与我所做的相似的代码。我只是想先确定一下这个概念。谢谢。
以上来自于百度翻译 以下为原文 Thank you for your reply, You'd say yes to using a software to send data from server ? And for the code I'll try to make up some code similar to what I did. I just want to make sure of the concept first. Thanks |
|
|
|
|
|
我的意思是“准备好你的数据(字节数组)并把它传递给sEnter()函数”
以上来自于百度翻译 以下为原文 I meant yes to "prepare your data (array of byte) and pass it to the send() function" |
|
|
|
|
|
好的,谢谢,你有选择端口和IP地址的想法吗?当我们从客户端打开一个套接字时,我们应该指定一个端口和一个IP地址(目的地),并且我们从服务器端执行同样的操作,两个套接字的端口是相同的。
以上来自于百度翻译 以下为原文 Okay thank you , and do you have any idea about choosing ports and IP addresses ? I mean when we open a socket from the client side we should specify a port and an IP address (of destination) and we do the same from the server side , the port for both sockets is the same ? |
|
|
|
|
|
在发送时,通常不选择“本地”端口,只有在接收时,作为端口“发送”,我会选择一个在1024以上(主要保留为标准应用程序)…你可以在互联网上查看现有的应用程序,随机选择一个。
以上来自于百度翻译 以下为原文 You usually don't choose a "local" port when sending, only when receiving: and, as the port "to send to" I'd pick one above 1024 (mostly reserved for standard apps)... you can look on the internet for existing apps and choose one randomly |
|
|
|
|
|
好的,但是根据我在程序中使用的TCP/IP堆栈API,有两个函数来打开套接字(服务器和客户端),这些函数是这样写的:/ /调用从客户端SIDUppSocket TCPIpU.UppClient打开(Ipad AddisSyType AddiType,UDPX端口ReleTeP)打开套接字ORT,IpMulyAuthAddia*远程地址)/ /调用从服务器SIDUppSocket TCPIpU.UpPyServEnter打开IPocket(IP-AddiSrsAdType AddiType,UDPX端口LocalPoad,IpMulyAuthAddioLocalAdvor)
以上来自于百度翻译 以下为原文 Okay but according to the TCP/IP stack API I am using in my program there are functions to open sockets for both sides (server and client) and these functions are written this way : // called to open socket from the client side UDP_SOCKET TCPIP_UDP_ClientOpen(IP_ADDRESS_TYPE addType, UDP_PORT remotePort, IP_MULTI_ADDRESS* remoteAddress) // called to open socket from the server side UDP_SOCKET TCPIP_UDP_ServerOpen(IP_ADDRESS_TYPE addType, UDP_PORT localPort, IP_MULTI_ADDRESS* localAddress) |
|
|
|
|
|
-要将客户端套接字连接到服务器套接字,需要服务器在端口上监听,客户端需要连接到该端口。所以:对于这个调用:TCPIpU-UPDPclitOnEnter(iPad AddisSyType AddiType,UppPixRealTePixPixMuleAddio*ReleToAdter)需要服务器正在监听的端口和该服务器的地址。你需要一个端口来侦听你在这里的选择,但是可能你不想选择一个标准的/众所周知的端口。而且,侦听的地址可以是0——除非您有多个接口,并且您关心哪一个要接受连接。对于服务器套接字发送数据,它需要一个相应的端口和IP地址来发送数据(类似于其他任何套接字)。当客户端连接到它时,此信息是可用的。如果没有客户端连接,则无法将数据发送到“空隙”。但是,可以使用ReloTyBin函数指定远程IP和端口,然后即使没有客户端连接到该套接字,也可以发送数据。但首选方法是:是打开客户端套接字,并开始向端口和IP地址发送数据。
以上来自于百度翻译 以下为原文 - To connect a client socket to a server socket you need the server listening on a port and the client connecting to that port. So: - For the call: TCPIP_UDP_ClientOpen(IP_ADDRESS_TYPE addType, UDP_PORT remotePort, IP_MULTI_ADDRESS* remoteAddress) you need the port the server is listening on and the address of that server. - For the call: TCPIP_UDP_ServerOpen(IP_ADDRESS_TYPE addType, UDP_PORT localPort, IP_MULTI_ADDRESS* localAddress) you need a port to listen on - your choice here, but probably you don't want to pick one of the standard/well known ports. And the address to listen on could be 0 - unless you have multiple interfaces and you care on which one you want to accept connections. For a server socket to send data, it needs a corresponding port and IP address to send data to (like any other socket for that matter). When a client connects to it, this info is available. If there's no client connected you cannot send data into the "void". But you can use the RemoteBind function to specify the remote IP and port and then you can send data even if there's no client connected to that socket. But the preferred approach is to open a client socket and start sending data to a port and IP address. |
|
|
|
|
|
|
|
|
|
|
|
好的,谢谢你们两个,我对IP地址了解不多,所以我在尽我最大的努力,所以对于我的远程地址,我手动设置地址:192.168100.55和我的本地地址:192.168100.101(只是随机的),并且对于我使用的端口相同:4001(随机选择),所以我是这样做的吗?正确的方法?谢谢你原谅我的无知:D
以上来自于百度翻译 以下为原文 Okay thanks both of you , I don't know much about IP addresses so I'm trying my best , so for my remote address I set manually the address : 192.168.100.55 and for my local address : 192.168.100.101 ( just randomly) and for the ports I used the same : 4001 (chosen randomly also) , so am I doing it the right way ? thank you and excuse me for my ignorance :d |
|
|
|
|
|
不完全是这样。远程地址(从客户端的角度来看)是服务器套接字正在监听的主机/机器的IP地址。所以,它是一个网络上的一个机器的IP地址。本地地址是指你当前所指的主机/机器的IP地址。显然,客户端和服务器套接字都驻留在具有IP地址的机器上。网络上的每台机器都应该有TCP/IP地址。可寻址并能与其他机器交谈。这些地址可以手动设置或由专用服务器(DHCP服务器)设置,这取决于网络。这可能是最好的开始,有一些网络基础。大量的书籍和在线文档可用。先尝试使用标准工具在机器/ PC上创建客户端& lt;-&;服务器连接,然后再跳到这种细节。
以上来自于百度翻译 以下为原文 Not quite. The remote address (from the client point of view) is the IP address of the host/machine where the server socket is listening. So, it's an IP address of a machine on a network. The local address means the IP address of the host/machine you're currently referring to - obviously both the client and the server sockets reside on machines that have an IP address. Each machine on a network should have a TCP/IP address in order to be addressable and to be able to talk to other machines. These addresses can be set manually or by special servers (DHCP servers), depending on the network. Probably this is the best place to start, with some networking basics. Plenty of books and on line documentation available. Try first creating a client <-> server connection on your machine/PC using standard tools before jumping into this kind of details. |
|
|
|
|
|
我认为这是很容易理解的。IP地址就像电话号码。端口就像一个电话扩展。UDP包就像一个短信(SMS)。TCP连接就像一个电话呼叫。IP地址标识你的PIC在网络上。你可能只有一个本地IP地址在你的PIC(所以有)。没有多少选择。由于您可能有许多任务,所以您可以使用端口号来区分不同的任务——与业务可能拥有单个电话号码相同的方式,然后使用扩展来区分工人。您可以将UDP消息从任何地方发送到网络上的任何地方。对于UDP,没有服务器或客户端,只是对等体——就像在移动电话网络上传递文本消息一样。套接字不是物理实体。它们不存在于网络上,对外部词不可见。它们是软件实体——最有可能的框架中的数据结构,用于管理TCP/IP包。当打开服务器UDP套接字时,您会对框架说:“嘿,为我创建一个套接字。这里有我的电话号码(本地IP地址)和扩展(本地端口),如果有文本的话。SSAGE(UDP包)到达指定的地址,我想看到它。框架会说你正在听指定的“IP地址:端口”。当一个UDP数据包到来时,框架将数据包传递给任何正在监听它的人(如果有的话)。请注意,当打开套接字时,物理字中不会发生任何事情。发生的唯一事情就是为你看数据包的框架。当你打开一个客户端UDP套接字时,你会对框架说:“嘿,我要把文本消息(UDP包)发送到这个电话号码(远程IP地址)和扩展(远程端口)。我也想看到所有的文本消息(UDP包),将在回应“回来”。该框架将默默地将电话号码(本地IP地址)和扩展(本地端口)分配给您的套接字,这样当您发送某些东西时,就有可能做出响应。
以上来自于百度翻译 以下为原文 I think it's very easy to understand by analogy. IP address is like phone number. Port is like a phone extension. UDP packet is like a text (SMS) message. TCP connection is like a phone call. IP address identifies your PIC on the network. You probably have only one local IP address on your PIC (so there's not much choice ). Since you may have many tasks, you use port numbers to distinguish between different tasks - same way as a business may have a single phone number and then use extensions to distinguish between workers. You can send UDP messages from anywhere to anywhere on the network. For UDP, there's no servers or clients, just peers - same as passing text messages on the mobile phone networks. Sockets are not physical entities. They don't exist on network and are not visible to outside word. They're software entities - most likely data structures in the framework which are used by it to manage TCP/IP packets. When you open a server UDP socket, you say to the framework: "Hey, create a socket for me - here's my phone number (local IP address) and extension(local port), if there's a text message (UDP packet) coming to the specified address, I want to see it". Framework would say that you're listening on the specified "IP address:port". When a UDP packet comes, the framework passes the packet to whoever is listening for it, if any. Note that when you open a socket nothing happens in the physical word. The only thing that happens is framework watching for packets for you. When you open a client UDP socket, you say to the framework: "Hey, I'm going to send text messages (UDP packets) to this phone number(remote IP address) and extension(remote port). I also want to see all the text messages (UDP packets) which will come back in response". The framework will silently assign a phone number (local IP address) and extension (local port) to your socket, so that when you send something, it would be possible to respond. |
|
|
|
|
|
是的,因为很多原因比解释更容易,这就是为什么我要一些代码…因为OP谈论C++,所以*很容易…(我只在Windows中做了UDP……)
以上来自于百度翻译 以下为原文 Yeah, and for many reasons is easier done than explained That's why I was asking for some code... since OP's talking about C++, it *is* going to be very easy... (I only did UDP in Windows...) |
|
|
|
|
|
好了,非常感谢你们的帮助,我开始向你们学习。
以上来自于百度翻译 以下为原文 okay thank you so much for your help I started to learn things thanks to all of you ;) |
|
|
|
|
|
再次问好,所以我想测试UDP客户端程序,调试时一切看起来都很好,但是当我使用笔记本电脑(用来配置IP地址,即使我真的不知道这个笔记本电脑到底做了什么)无论如何,这个笔记本电脑通过2个交叉电缆VI连接到我的微控制器(客户端)。A开关,当我从这个笔记本电脑ping IP地址为我的客户是192.168100.101没有数据包。谁能帮我解决问题?
以上来自于百度翻译 以下为原文 Hello again, so I want to test the udp client program and when debugging everything looks fine , but when I use a laptop ( used to configure the ip address even if I don't really get what this laptop does exactly) anyway this laptop is connected to my microcontroller (client) via 2 crossed cables via a switch , when I ping from this laptop the ip address for my client which is 192.168.100.101 there are no packets sent. can anyone help me figure out the problem ? |
|
|
|
|
|
有些木板不喜欢交叉电缆…嗯,我不确定你现在到底是什么意思!更好地描述你的情景。
以上来自于百度翻译 以下为原文 Some boards don't like the crossed cables... well, I am not sure what you mean exactly now! Describe your scenario better. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
514 浏览 0 评论
5819 浏览 9 评论
2351 浏览 8 评论
2238 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3546 浏览 3 评论
1170浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1124浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
893浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
514浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-18 14:06 , Processed in 1.285284 second(s), Total 80, Slave 73 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2057