简体   繁体   中英

Winsock2.h Connecting to ip address without passing it on command line

While I was checking basic use for winsock2.h library I asked myself how can i make program that connect automatically to IP address passed in source code without typing the address in command line all the time

As @AlbertShown says in his comment, you can manually provide the results of the getaddrinfo() function to whichever function needs them. You just need to have a look at the results it gives you when you do run it, and make sure and sure the appropriate protocol family, protocol and socket type. Here's an example program using these fields.

However - this is not a useful thing to do. You wrote in a comment that you want to "make things faster" - remember the maxim: "Premature optimization is the root of all evil."

Is your program actually being slowed down by running getaddrinfo() ? How much of the program's execution time does calling this function take? Use a profiler, or place a timer in your code, and figure this out. I'm sure you'll find it is a lot less than you think. It is almost certainly not worth bothering avoiding this function call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM