c / c ++中的udp客户端服务器应用程序

问题描述:

嘿,

我是网络编程的初学者,所以我很抱歉,如果我的问题看起来非常简单而且对你很愚蠢......

我的第一个任务是运行一个简单的udp客户端服务器应用程序,通常我看到的示例程序是在命令行参数的帮助下运行的,但是在基本级别我不想这样做,所以我需要用一些IP地址绑定客户端(srever) '的IP地址和端口号)...

如何在代码中执行此操作...以便我无需在命令提示符下运行它...

如果我得到了服务器和客户端的答案,那我真的很有意思。

再次为这样一个原始问题道歉:(

hey,
I am a beginner to network programming so my apologies if my question seems very trivial and dumb to you...
my first task is to run a simple udp client server application,usually the sample programs that I see run with the help of command line arguments,but being on the basic level I do not want to do that,so I need to bind the client with some IP address(srever''s IP address and port number)...
how can I do that in code...so that I need not run it from command prompt...
I would be really thatnkful if I got the answer for both server and client.
again my apologies for a primitive question like this:(

好吧,如果你不想在你的应用程序中处理命令行参数(但为什么?)然后在代码中硬连接这些参数。例如,使用这个代码示例 [ ^ ],从
Well, if you don''t want to deal with command line arguments (but why?) in your application then hard-wire such parameters in code. For instance, using this code sample[^], change (in the client code) from
h = gethostbyname(argv[1]);



to


to

h = gethostbyname("127.0.0.1");