|
-
Dec 19th, 2000, 01:09 PM
#1
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

Thanks,
Dennis
-
Dec 19th, 2000, 09:57 PM
#2
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
-
Dec 20th, 2000, 01:21 PM
#3
Monday Morning Lunatic
Version 2 is definitely the one to go for. Although, make sure you link with winsock.lib.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 20th, 2000, 02:01 PM
#4
Monday Morning Lunatic
Whoops...no it isn't!!!!!
Header: Declared in Winsock2.h.
Library: Use Ws2_32.lib.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 20th, 2000, 02:22 PM
#5
how do I add a lib file to my project?(VC++6)
-
Dec 20th, 2000, 02:40 PM
#6
Monday Morning Lunatic
Project Settings, then the Link tab. Then add it to the text box for "Object/Library Modules".
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 20th, 2000, 02:51 PM
#7
cool,
thanks,
what functions and stuff do I use.. to connect... to recieve data... etc.?
-
Jan 2nd, 2001, 04:33 PM
#8
Does anyone have any WinSock tutorials?
-
Jan 2nd, 2001, 04:46 PM
#9
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.
Code:
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.
-
Jan 4th, 2001, 08:04 PM
#10
Frenzied Member
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?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 4th, 2001, 09:39 PM
#11
here is a very simple C++ program that uses windows.. it's a DOS console app...
Code:
include <windows.h>
int main()
{
MessageBox(NULL, "Test", "Test", MB_OK);
return 0;
}
windows.h has the most common API's already declared...
-
Jan 5th, 2001, 07:56 AM
#12
Frenzied Member
I know they're in windows.h, but can I declare them without the .h file? so my app stays as small as possible?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Jan 5th, 2001, 10:00 AM
#13
Frenzied Member
Maybe this can be an answer to Jop's question. Less memory ,smaller exe
Code:
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.
-
Jan 5th, 2001, 10:03 AM
#14
Frenzied Member
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
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|