Page 1 of 1

How to add a new socket?

Posted: 03 Dec 2009 12:50
by brizio
Hi all,
i want to create another thread in vlc 1.0.2 which contains a socket listening on a port for some encoder parameters used by vlc during the encoding, with the aim of change them at runtime, without kill the encoder process..
I'm compiling on WinXP using MINGW http://wiki.videolan.org/Win32CompileMSYSNew
I can successfully compile the source code, but know i've added the code for the new socket (it's not ended but just for test)

Code: Select all

#include <sys/types.h> #include <unistd.h> #include <sys/socket.h> #include <sys/uio.h> #include <sys/un.h> #include <netinet/in.h> #include <pthread.h> ... ... static int StartSocket( ) { struct sockaddr_in server,client; char buffer[50]; int socket = socket (AF_INET, SOCK_STREAM, 0); server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons(SERVER_PORT); bind(socket, (struct sockaddr *)&server, sizeof(server)); listen(socket, 1); while(1) { int req=accept(sock, (struct sockaddr *)&client, &client_len); int lenght=recv(req, buffer, 50, 0); } }
in compiling phase, minsys can't find sys/socket.h,sys/uio.h,sys/un.h,netinet/in.h

Should i use a predefined types for vlc instead the one i've done? I've seen that in other files of source code the included file which are missing, seems to be correctly found....
Thanks for your help!

brizio

Re: How to add a new socket?

Posted: 03 Dec 2009 13:49
by thannoy
You added POSIX code while Windows platform is not POSIX compliant.
To open a socket on windows, you have to cope with Windows API (windows.h, MSDN, etc).

You can also bind your code with a POSIX emulation layer which cope with Window API for you.
@see Win32CompileCygwinNew#POSIX_emulation_layer
@see "MSDN socket" web search
@see http://en.wikipedia.org/wiki/C_POSIX_library

Re: How to add a new socket?

Posted: 03 Dec 2009 18:52
by brizio
thank you very much for your help,the use of windows's socket does not create problems in compiling phase.
Excuse me for the duplicated post!