As far as I know, you can use Windows headers, that on TCP are very
similar to Linux ones. Well, not by header names, but you'll find a
socket, listen, accept, setsockopt, etc. functions with same arguments,
and so on: you'll only need to use send intead of write and recv intead of
read to do I/O on socket. This is the way Microsoft wished to be posix 1.0
compliant.
To do this you need to link a lib (winsock, or something similar, which
you should initialize before any network call with WSASturtup) and a
network header, but I don't remember its name. If you give a look on MSDN
on line. i.e. searching for socket: data over there are VisualC-oriented,
but Dev C++'s behaviour is identical.
I hope that's helpful to you.
Bye, Ferdinando
On Tue, 28 Oct 2003, Alain Paschoud wrote:
> Hi all,
>
> I'm new to dev-cpp, and I need to accept a TCP connection. As I did under
> Linux, I will use the bind and accepts functions. But to do that, I need to
> include the <sys/socket.h> header file. I did it (see below), but there is
> no socket.h file in the include directory of dev-cpp (result : accept_con.c
> sys\socket.h: No such file or directory). Here are my questions :
>
> Is there every required headers with Dev-cpp to do network programming ?
> Is there every necessary libraries ?
> Do I have to download something more to use sockets ?
>
> Best regards, and thank you for any help.
>
> Alain Paschoud
>
> **** Code example below ****
>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/socket.h>
>
> #define MYPORT 3490
>
> int accept_con()
> {
> int sockfd;
> struct sockaddr_in my_addr;
>
> sockfd = socket(AF_INET, SOCK_STREAM, 0); // do some error checking!
>
> my_addr.sin_family = AF_INET; // host byte order
> my_addr.sin_port = htons(MYPORT); // short, network byte order
> my_addr.sin_addr.s_addr = htons(INADDR_ANY);
> memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct
>
> // don't forget your error checking for bind():
> bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr));
>
> /* Accept connection */
> accept(sockfd, (struct sockaddr *) &my_addr, sizeof(struct
> sockaddr));
> }
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|