Do I need to download a library for using sockets on Windows?

  • Thread starter sneez
  • Start date
  • Tags
    Windows
In summary, to use sockets on Windows, you need to link to the library Ws2_32.lib. This library is present in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib directory. The #include directive is not used for libraries, as they are linked by the compiler. You can find more information on using sockets on Windows in the MSDN documentation.
  • #1
sneez
312
0
Im trying to play with sockets on windows

what lib do i need to link to make this statement work? Does it come with win or do i have to download it?



WSAStartup(MAKEWORD(1,1), &wsa);
 
Computer science news on Phys.org
  • #3
Thanx enathan, i have that library in my windows/system32 dir but when i try to compile program using the above code it says link error.

Why is that. I can use socket dlls and stuff but not this ? something I am doing wrong...?
 
  • #4
I am assuming you are using C# or C++

You have to tell the compiler to include the library somehow. I think the keyword (or drective) is #Include <library>; I forget lol I have not programmed C# for a long time.

What exactly is the compiler error BTW?
 
  • #5
The .dll is not a library -- it's a shared object. You need to link against the .lib file corresponding to the .dll, which provides all the signatures for linking. You also do not use the #include directive for anything involving libraries; the #include directive affects the source, and only the compiler deals with the source itself. The linker deals with the resulting object files, and has nothing to do with the source.

You need to link against the library Ws2_32.lib, present (on my Windows XP SP2 machine) in C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib

In the future, please use MSDN to search for documentation: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsastartup_2.asp [Broken]

- Warren
 
Last edited by a moderator:
  • #6
thanx a lot

:d
 

1. What are Windows sockets?

Windows sockets, also known as Winsock, are an application programming interface (API) that allows programs to communicate over a network. It is used for developing internet-based applications on the Windows operating system.

2. How do I create a Windows socket?

To create a Windows socket, you will need to use the socket() function from the Winsock API. This function creates a socket endpoint and returns a socket descriptor, which can be used for various socket operations.

3. What are the different types of Windows sockets?

There are two main types of Windows sockets: stream sockets and datagram sockets. Stream sockets are used for reliable, two-way communication between two hosts, while datagram sockets are used for unreliable, one-way communication.

4. How do I handle errors with Windows sockets?

Errors with Windows sockets are handled by using the WSAGetLastError() function, which retrieves the error code associated with the last failed Winsock function. This error code can then be translated into a human-readable error message using the FormatMessage() function.

5. Can Windows sockets be used for both IPv4 and IPv6?

Yes, Windows sockets can be used for both IPv4 and IPv6 communication. The protocol family used for IPv4 is AF_INET, while the protocol family used for IPv6 is AF_INET6. The same Winsock functions can be used for both types of communication.

Similar threads

  • Computing and Technology
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
844
  • Computing and Technology
Replies
5
Views
2K
  • Computing and Technology
2
Replies
37
Views
5K
  • Computing and Technology
Replies
18
Views
2K
  • Computing and Technology
Replies
9
Views
903
Replies
1
Views
1K
Replies
9
Views
3K
  • Programming and Computer Science
Replies
1
Views
323
  • Computing and Technology
Replies
12
Views
2K
Back
Top