与某些接口的UDP通信(使用UDP Echo示例代码,main.m有问题)
我已经从 Apple 下载了 UDPEcho 示例代码,以便与设备建立简单的 UDP“连接”。我可以在提供的 main.m 上设置设备的 IP 和端口来建立“连接”。分析我的控制台,我什至从我从 main.m 发送的所有内容中得到了设备的积极响应。
我的问题是 main.m 按原样不加载任何 .xib。我尝试修改它并放入 UIApplicationMain (argc,argv,nil,nil)
等内容,但在这种情况下,我加载了默认的 .xib (带有我的 PrjctViewController ),但我不这样做在控制台上没有得到任何响应。在这种情况下根本就没有 UDP 连接。
我如何使用 UDPEcho 示例来设置与某些用户界面的简单 UDP“连接”?一些简单的事情,例如用户能够输入 IP 和端口并从设备获取一些响应并显示在屏幕上。通信不是问题,因为我在控制台中得到响应,整个问题是在使用此示例代码时设置一些简单的界面。我不知道如何在保持连接的同时“覆盖”main.m 来加载 .xib。我已经尝试将所有函数从 main.m 传递到我的 PrjctViewController 但这似乎并不能解决我的问题。如果有人有一些例子向我展示或想法来启发我,我将非常感激。
I´ve downloaded the UDPEcho sample code from Apple to make a simple UDP "connection" with a device.. I´m able to make a "connection" setting the ip and port of my device on the main.m provided. Analyzing my console i´m even getting a positive response from the device from everything i´m sending from main.m.
My problem is that main.m as is doesn´t load any .xib. I have tried to modify it and put the UIApplicationMain (argc,argv,nil,nil)
and stuff, but in that case i got my default .xib (with my PrjctViewController ) to load but i don´t get any response on the console. In that case there is no UDP connection at all.
How can i use UDPEcho sample to set a simple UDP "connection" with some user interface? Something simple like the user being able to enter a ip and a port and getting some response from the device to be shown in the screen. The communication is not the problem, as i´m getting responses in the console, the whole problem is setting some simple interface while using this sample code. I don´t know how i can "override" main.m to load a .xib while maintaining my connection. I´ve already tried to pass all functions from main.m to my PrjctViewController but that doesn´t seem to solve my problem. If anybody has some example to show me or ideas to enlighten me up i´ll be very thankfull.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在应用程序启动、视图控制器初始化或按钮事件委托之一中启动连接内容。异步处理连接,或者在后台线程中处理,以免阻塞 UI 线程。
Start the connection stuff in one of the app launch, view controller init, or button event delegates. Handle the connection asynchronously, or in a background thread, so as not to block the UI thread.
不要在 main.m 中进行连接操作。像往常一样创建 iPhone 应用程序,并将连接创建代码移至用户输入的处理函数中。例如,用户输入 IP 等并单击“Go”按钮。将连接设置放入“Go”按钮的处理程序中。
Don't do the connection stuff in main.m. Create your iPhone app as usual, and move the connection-creation code into a handler function for the user input. For instance, the user enters IP etc and clicks a 'Go' button. Put the connection setup into the handler for the 'Go' button instead.
对于未来的项目,请查看 CocoaAsyncSocket
For future project take a look at CocoaAsyncSocket