head 1.7; access; symbols start:1.1.1.1 blursoft:1.1.1; locks; strict; comment @// @; 1.7 date 2002.10.31.18.39.58; author steven; state Exp; branches; next 1.6; 1.6 date 2002.10.30.20.33.41; author steven; state Exp; branches; next 1.5; 1.5 date 2002.10.30.18.18.27; author steven; state Exp; branches; next 1.4; 1.4 date 2002.10.29.20.54.34; author steven; state Exp; branches; next 1.3; 1.3 date 2002.10.29.18.05.14; author steven; state Exp; branches; next 1.2; 1.2 date 2002.10.24.00.19.46; author steven; state Exp; branches; next 1.1; 1.1 date 2002.10.21.14.58.28; author steven; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2002.10.21.14.58.28; author steven; state Exp; branches; next ; desc @@ 1.7 log @stuff @ text @#include #include #include #include "blimpsrv.h" #include "winamp.h" #include "winamputil.h" #define RCVBUFSIZE 32 #define MAXPENDING 5 /* Maximum outstanding connection requests */ HWND hwin_amp; //global handle DWORD WINAPI handle_client( LPVOID lpParam ) { char buf[ RCVBUFSIZE ]; int recvMsgSize; char buffer[10] = {'\0'}; extern int update_interval; int clntSocket = *(int *)lpParam; printf("within, the socket is %d address is %d\n",clntSocket,lpParam); if( (recvMsgSize = recv(clntSocket, buf, RCVBUFSIZE, 0)) < 0 ){ fprintf(stderr,"error receiving message\n"); exit(1); } while( recvMsgSize > 0 ){ /* a zero indicates end-of-transmission */ printf("telling client's winamp to start...\n"); send(clntSocket,"IPC_STARTPLAY",13,0); for( ;; ) { int res = get_output_time( hwin_amp ); itoa(res,buffer,10); printf("position is: %d\n",res); send(clntSocket,buffer,10,0); Sleep( update_interval ); } if((recvMsgSize = recv(clntSocket,buf,RCVBUFSIZE,0)) < 0 ){ fprintf(stderr,"error in receiving\n"); exit(1); } } closesocket(clntSocket); return EXIT_SUCCESS; } void launch_thread_handler( int clntSocket ) { DWORD dwThreadId; int *param = (int *)malloc(sizeof(int) * 1); //mem leak. free it somewhere *param = clntSocket; printf("param is %d address is %d\n",param,¶m); HANDLE hThread = CreateThread( NULL, // default security attributes 0, // use default stack size handle_client, // thread function param, // argument to thread function 0, // use default creation flags &dwThreadId // returns the thread identifier ); if( hThread == NULL ){ fprintf(stderr,"thread creation failed\n"); } printf("leaving launch_thread_handler()\n"); } int start_server( ) { int servSock; int clntSock; struct sockaddr_in echoServAddr; struct sockaddr_in echoClntAddr; unsigned short echoServPort; int clntLen; WSADATA wsaData; echoServPort = 32379; if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { fprintf(stderr, "WSAStartup() failed"); exit(1); } if ((servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){ fprintf(stderr,"socket() failed"); exit(1); } memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */ echoServAddr.sin_family = AF_INET; /* Internet address family */ echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */ echoServAddr.sin_port = htons(echoServPort); /* Local port */ if (bind(servSock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0){ fprintf(stderr,"error in bind\n"); exit(1); } if (listen(servSock, MAXPENDING) < 0){ fprintf(stderr,"listen failed\n"); exit(1); } for (;;) { clntLen = sizeof( echoClntAddr ); /* LISTEN UNTIL A CLIENT COMES IN */ if ((clntSock = accept(servSock, (struct sockaddr *) &echoClntAddr, &clntLen)) < 0){ fprintf(stderr,"error in accept\n"); exit(1); } hwin_amp = get_winamp_handle( ); set_playlist_to_beginning( hwin_amp ); start_playing_winamp( hwin_amp ); printf("Handling client %s\n", inet_ntoa(echoClntAddr.sin_addr)); printf("before, socket was %d\n",clntSock); launch_thread_handler( clntSock ); } /* NOT REACHED */ } @ 1.6 log @More changes all around. Added a 'path_to_winamp' option for the client so that winamp can automatically be started if it's not already. Also added more winamputil functions to open_winamp. @ text @d64 3 a66 3 NULL, // default security attributes 0, // use default stack size handle_client, // thread function d68 2 a69 2 0, // use default creation flags &dwThreadId // returns the thread identifier d82 7 a88 7 int servSock; /* Socket descriptor for server */ int clntSock; /* Socket descriptor for client */ struct sockaddr_in echoServAddr; /* Local address */ struct sockaddr_in echoClntAddr; /* Client address */ unsigned short echoServPort; /* Server port */ int clntLen; /* Length of client address data structure */ WSADATA wsaData; /* Structure for WinSock setup communication */ @ 1.5 log @Got the CreateThread() stuff working. So clients can now connect at any time and start playing. DOesn't perfectly work and I might need to do more testing, but much further now. Also added the ability to specifiy the server address as dotted-quad or server name. Simple, but that took me awhile. People should laugh at that. @ text @d12 1 a17 1 HWND hwin_amp; d31 5 a35 10 int input = 0; printf("press 1 to start winamp\n"); scanf("%d",&input); if( input == 1 ){ printf("telling winamp to start...\n"); send(clntSocket,"IPC_STARTPLAY",13,0); } hwin_amp = get_winamp_handle( ); d44 1 a44 5 /* if( send( clntSocket, buf, recvMsgSize, 0) != recvMsgSize){ fprintf(stderr,"error sending back to client\n"); exit(1); */ d131 5 @ 1.4 log @Added per-client threading for the server connections. Compiles, but doesn't work :( @ text @d21 1 d67 5 a71 3 DWORD dwThreadId, dwThrdParam; dwThrdParam = clntSocket; d76 1 a76 1 &dwThrdParam, // argument to thread function d80 4 a83 1 d133 1 a133 1 clntLen = sizeof(echoClntAddr); d137 3 a139 3 fprintf(stderr,"error in accept\n"); exit(1); } d141 1 a141 1 @ 1.3 log @Added winamputil files to abstract some of the ugliness of SendMessage away. Added a -? option to print the usage and program name. Also made sure that if the user uses some incorrect options the show_usage() is called. Also made various cleanups. @ text @d13 1 a13 1 void handle_client(int clntSocket) d20 1 d59 1 a59 1 return; d62 21 d118 1 a118 1 d123 1 a123 1 Sleep( 5000 ); d129 1 a129 1 d135 3 a137 1 handle_client(clntSock); @ 1.2 log @Changed how we handle the commandline. Also added *some* error checking. Paved the way for the client to connect to a specified server (instead of having it hardcoded). Also made an update_interval to specify when updates should be done to the winamp position. @ text @d1 117 a117 123 /* CHANGES FROM UNIX VERSION */ /* */ /* 1. Changed header files */ /* 2. Added WSAStartUP() and WSACleanUp(). */ #include /* for printf(), fprintf() */ #include /* for socket(),... */ #include /* for exit() */ #include "blimpsrv.h" #include "winamp.h" #define RCVBUFSIZE 32 #define MAXPENDING 5 /* Maximum outstanding connection requests */ void handle_client(int clntSocket) { char buf[ RCVBUFSIZE ]; int recvMsgSize; int res; HWND hwnd_winamp; char buffer[10] = {'\0'}; extern int update_interval; if( (recvMsgSize = recv(clntSocket, buf, RCVBUFSIZE, 0)) < 0 ){ fprintf(stderr,"error receiving message\n"); exit(1); } while( recvMsgSize > 0 ){ int input = 0; printf("press 1 to start winamp\n"); scanf("%d",&input); if( input == 1 ){ printf("telling winamp to start...\n"); send(clntSocket,"IPC_STARTPLAY",13,0); } hwnd_winamp = FindWindow("Winamp v1.x",NULL); for( ;; ) { int res = SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GETOUTPUTTIME); itoa(res,buffer,10); printf("position is: %d\n",res); send(clntSocket,buffer,10,0); Sleep( update_interval ); } /* if( send( clntSocket, buf, recvMsgSize, 0) != recvMsgSize){ fprintf(stderr,"error sending back to client\n"); exit(1); */ if((recvMsgSize = recv(clntSocket,buf,RCVBUFSIZE,0)) < 0 ){ fprintf(stderr,"error in receiving\n"); exit(1); } } closesocket(clntSocket); return; } int start_server( ) { int servSock; /* Socket descriptor for server */ int clntSock; /* Socket descriptor for client */ struct sockaddr_in echoServAddr; /* Local address */ struct sockaddr_in echoClntAddr; /* Client address */ unsigned short echoServPort; /* Server port */ int clntLen; /* Length of client address data structure */ WSADATA wsaData; /* Structure for WinSock setup communication */ echoServPort = 32379; if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { fprintf(stderr, "WSAStartup() failed"); exit(1); } if ((servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){ fprintf(stderr,"socket() failed"); exit(1); } memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */ echoServAddr.sin_family = AF_INET; /* Internet address family */ echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */ echoServAddr.sin_port = htons(echoServPort); /* Local port */ if (bind(servSock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0){ fprintf(stderr,"error in bind\n"); exit(1); } if (listen(servSock, MAXPENDING) < 0){ fprintf(stderr,"listen failed\n"); exit(1); } Sleep( 5000 ); for (;;) { clntLen = sizeof(echoClntAddr); if ((clntSock = accept(servSock, (struct sockaddr *) &echoClntAddr, &clntLen)) < 0){ fprintf(stderr,"error in accept\n"); exit(1); } printf("Handling client %s\n", inet_ntoa(echoClntAddr.sin_addr)); handle_client(clntSock); } /* NOT REACHED */ } @ 1.1 log @Initial revision @ text @d24 3 a26 1 d50 1 a50 1 Sleep( 3000 ); @ 1.1.1.1 log @Blimp Project @ text @@