Click to See Complete Forum and Search --> : windows sockets
how do I use winsock in C++?
I would search my lib directory for something, but I am at school right now, and all they have is Turbo C++ 4.5
:eek:
Thanks,
Dennis
Ok,
I found winsock1.h and winsock2.h
which one should I use for simple TCP/IP communication(just for chat programs and stuff)?
and if you know that.. what functions should i use, and how should I use them?
and one more thing, do I need to add anything else to my project to make it work??
Thanks,
Dennis Wrenn
PS: using visual C++ 6 enterprise
parksie
Dec 20th, 2000, 12:21 PM
Version 2 is definitely the one to go for. Although, make sure you link with winsock.lib.
parksie
Dec 20th, 2000, 01:01 PM
Whoops...no it isn't!!!!!
Header: Declared in Winsock2.h.
Library: Use Ws2_32.lib.
how do I add a lib file to my project?(VC++6)
parksie
Dec 20th, 2000, 01:40 PM
Project Settings, then the Link tab. Then add it to the text box for "Object/Library Modules".
cool,
thanks,
what functions and stuff do I use.. to connect... to recieve data... etc.?
Does anyone have any WinSock tutorials?
I don't... but I am looking too....
I asked someone.. and they said to use these functions(easier then the WSA--- ones)
Socket Functions
The Windows Sockets specification includes all the following Berkeley-style socket routines that were part of the Windows Sockets 1.1 API.
Routine Meaning
accept1 An incoming connection is acknowledged and associated with an immediately created socket. The original socket is returned to the listening state.
bind Assigns a local name to an unnamed socket.
closesocket Removes a socket from the per-process object reference table. Only blocks if SO_LINGER is set with a nonzero time-out on a blocking socket.
connect1 Initiates a connection on the specified socket.
getpeername Retrieves the name of the peer connected to the specified socket.
getsockname Retrieves the local address to which the specified socket is bound.
getsockopt Retrieves options associated with the specified socket.
htonl2 Converts a 32-bit quantity from host-byte order to network-byte order.
htons2 Converts a 16-bit quantity from host-byte order to network-byte order.
inet_addr2 Converts a character string representing a number in the Internet standard ".'' notation to an Internet address value.
inet_ntoa2 Converts an Internet address value to an ASCII string in ".'' notation that is, "a.b.c.d''.
ioctlsocket Provides control for sockets.
listen Listens for incoming connections on a specified socket.
ntohl2 Converts a 32-bit quantity from network-byte order to host-byte order.
ntohs2 Converts a 16-bit quantity from network byte order to host byte order.
recv1 Receives data from a connected or unconnected socket.
recvfrom1 Receives data from either a connected or unconnected socket.
select1 Performs synchronous I/O multiplexing.
send1 Sends data to a connected socket.
sendto1 Sends data to either a connected or unconnected socket.
setsockopt Stores options associated with the specified socket.
shutdown Shuts down part of a full-duplex connection.
socket Creates an endpoint for communication and returns a socket descriptor.
1 The routine can block if acting on a blocking socket.
2 The routine is retained for backward compatibility with Windows Sockets 1.1, and should only be used for sockets created with AF_INET address family.
Jop
Jan 4th, 2001, 07:04 PM
Hey Dennis, there are API calls for Winsock, take a look at the API-Guide, you know how to translate them from VB to C++ right?
Is it possible to declare API calls (just like in VB), or do you really have to use those .h files (extra bytes to the actual exe right?)
ok I have to admit I'm learning VC++ since yesterday ;)
Hey Dennis, please add me to your ICQ again, or aren't you online anytime?
here is a very simple C++ program that uses windows.. it's a DOS console app...
include <windows.h>
int main()
{
MessageBox(NULL, "Test", "Test", MB_OK);
return 0;
}
windows.h has the most common API's already declared...
Jop
Jan 5th, 2001, 06:56 AM
I know they're in windows.h, but can I declare them without the .h file? so my app stays as small as possible?
Vlatko
Jan 5th, 2001, 09:00 AM
Maybe this can be an answer to Jop's question. Less memory ,smaller exe
All you do is, before you include your header files,
#define WIN32_LEAN_AND_MEAN
And magically, your program compiles much faster and uses less memory. How?
All this does is excludes some rarely-used stuff from being processed by the compiler. Specifically, the following header files are not included when WIN32_LEAN_AND_MEAN is defined:
cderr.h
dde.h
ddeml.h
dlgs.h
lzexpand.h
mmsystem.h
nb30.h
rpc.h
shellapi.h
winperf.h
winsock.h, mswsock.h, or winsock2.h
wincrypt.h
commdlg.h
winspool.h
ole.h or ole2.h
This information is found in windows.h lines 132-165.
Note that if you want to have the lean and mean advantages, but you need to use something that is excluded in it, such as the Shell API (maybe for system tray) or winsock, it's usually safe to simply #include the appropriate header file in your program after defining WIN32_LEAN_AND_MEAN.
NOTE: I know the experts out there will complain that there is no reason why WIN32_LEAN_AND_MEAN would reduce memory usage. However, I have found in my tests that it actually does reduce it slightly. If anyone has the free time to do further research, I would update this page accordingly.
Jop
Jan 5th, 2001, 09:03 AM
Thanks Vlatko, can you help me with this q?
http://209.207.250.147/showthread.php?threadid=47496
thanx ;)
I gave you the VB source, now you give me the C++ source? Now that's what I call recycling ;)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.