head 1.10; access; symbols start:1.1.1.1 blursoft:1.1.1; locks; strict; comment @// @; 1.10 date 2002.11.01.19.12.26; author steven; state Exp; branches; next 1.9; 1.9 date 2002.10.31.18.39.58; author steven; state Exp; branches; next 1.8; 1.8 date 2002.10.30.20.33.41; author steven; state Exp; branches; next 1.7; 1.7 date 2002.10.30.18.18.27; author steven; state Exp; branches; next 1.6; 1.6 date 2002.10.29.20.54.34; author steven; state Exp; branches; next 1.5; 1.5 date 2002.10.29.18.05.14; author steven; state Exp; branches; next 1.4; 1.4 date 2002.10.28.20.49.12; author steven; state Exp; branches; next 1.3; 1.3 date 2002.10.24.00.19.46; author steven; state Exp; branches; next 1.2; 1.2 date 2002.10.23.23.26.42; 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.10 log @Added a client threshold option to set the update threshold. Also added three files so that the project can be opened with Vis Stud .NET @ text @/* CHANGES FROM UNIX VERSION */ /* */ /* 1. Changed header files. */ /* 2. Added WSAStartUP() and WSACleanUp(). */ /* 3. Used closesocket() instead of close(). */ #include /* for printf(), fprintf() */ #include /* for socket(),... */ #include /* for exit() */ #include #include "blimpcli.h" #include "winamp.h" #include "winamputil.h" #define RCVBUFSIZE 32 /* Size of receive buffer */ unsigned long get_server_ip( char *address ) { struct hostent *hostinfo; hostinfo = gethostbyname( address ); if( hostinfo == NULL ){ fprintf(stderr,"couldn't resolve server's IP address\n"); exit(EXIT_FAILURE); } return *((unsigned long *)hostinfo->h_addr_list[0]); } int start_client( ) { int sock; struct sockaddr_in echoServAddr; unsigned short echoServPort; unsigned long servIP; char *echoString; char echoBuffer[RCVBUFSIZE]; int echoStringLen; int bytesRcvd, totalBytesRcvd; WSADATA wsaData; extern char *server_address; extern int cli_thresh; echoString = "running"; echoServPort = 32379; echoStringLen = strlen(echoString); if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) /* Load Winsock 2.0 DLL */ { fprintf(stderr, "WSAStartup() failed"); exit(1); } if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) printf("socket() failed"); servIP = get_server_ip( server_address ); memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */ echoServAddr.sin_family = AF_INET; /* Internet address family */ echoServAddr.sin_addr.s_addr = servIP; /* Server IP address */ echoServAddr.sin_port = htons(echoServPort); /* Server port */ /* CONNECT TO THE SERVER ON PORT 32379 */ if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0){ fprintf(stderr,"Unable to connect to server. Make sure it's running."); exit( EXIT_FAILURE ); } /* SEND THE SERVER THE STRING 'RUNNING' TO LET IT KNOW CLIENT STATUS */ if (send(sock, echoString, echoStringLen, 0) != echoStringLen){ fprintf(stderr,"send() sent a different number of bytes than expected"); exit( EXIT_FAILURE ); } HWND hwin_amp = get_winamp_handle( ); if( hwin_amp == NULL ){ fprintf(stderr,"Unable to get a handle to Winamp. Firing up Winamp...\n"); if( open_winamp( ) == 0){ fprintf(stderr,"You'll have to start Winamp manually. I can't do it :( \n"); exit( EXIT_FAILURE ); } else{ hwin_amp = get_winamp_handle( ); if( hwin_amp == NULL ){ fprintf(stderr, "Still can't get handle\n"); exit( EXIT_FAILURE ); } } } while( strcmp(echoBuffer,"quit") != 0 ){ echoStringLen = strlen(echoString); totalBytesRcvd = 0; while (totalBytesRcvd < 10) { if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0){ fprintf(stderr,"recv() failed or connection closed prematurely"); exit( EXIT_FAILURE ); } totalBytesRcvd += bytesRcvd; /* Keep tally of total bytes */ echoBuffer[bytesRcvd] = '\0'; /* Add \0 so printf knows where to stop */ } if( strcmp(echoBuffer,"IPC_STARTPLAY") == 0 ){ printf("I have been told to start playing winamp\n"); int pos = get_playlist_position( hwin_amp ); set_playlist_position( hwin_amp, pos ); start_playing_winamp( hwin_amp ); } else{ int res = get_output_time( hwin_amp ); printf("the server's position is %d and the client is at %d\n",atoi(echoBuffer),res); if( abs(atoi(echoBuffer) - res) > cli_thresh ){ printf("DOSYNC >> difference was greater than %d, setting client\n",cli_thresh); jump_to_time( hwin_amp, atoi(echoBuffer) ); } else printf("nosync >> no need to sync, they should be doing well now...\n"); } }//while closesocket(sock); WSACleanup(); /* Cleanup Winsock */ exit( EXIT_SUCCESS ); } @ 1.9 log @stuff @ text @d45 1 d117 2 a118 2 if( abs(atoi(echoBuffer) - res) > 500 ){ printf("difference was greater than 1000, setting client\n"); d122 1 a122 1 printf("no need to sync, they should be doing well now...\n"); @ 1.8 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 @d35 9 a43 9 int sock; /* Socket descriptor */ struct sockaddr_in echoServAddr; /* Echo server address */ unsigned short echoServPort; /* Echo server port */ unsigned long servIP; /* Server IP address (dotted quad) */ char *echoString; /* String to send to echo server */ char echoBuffer[RCVBUFSIZE]; /* Buffer for echo string */ int echoStringLen; /* Length of string to echo */ int bytesRcvd, totalBytesRcvd; /* Bytes read in single recv() and total bytes read */ WSADATA wsaData; /* Structure for WinSock setup communication */ d83 1 a83 1 else d85 5 a89 1 @ 1.7 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 @a27 2 d77 9 a85 3 if( hwin_amp == NULL ){ fprintf(stderr,"Unable to get a handle to WINAMP. Is it running?\n"); exit( EXIT_FAILURE ); d105 2 @ 1.6 log @Added per-client threading for the server connections. Compiles, but doesn't work :( @ text @d19 4 d24 8 d40 1 a40 1 char *servIP; /* Server IP address (dotted quad) */ a47 1 servIP = server_address; d60 2 a61 1 d64 1 a64 1 echoServAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */ @ 1.5 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 @d55 1 a55 1 d60 1 a60 1 @ 1.4 log @I added support for sync'ing only when the client and server are out of sync by a certain threshold. Lots more work to do, but the base is there. @ text @d13 1 d19 1 a19 5 HWND get_winamp_handle( void ) { HWND hwnd_winamp = FindWindow("Winamp v1.x",NULL); return hwnd_winamp; } d56 4 a59 2 if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) printf("connect() failed"); d61 10 a70 5 if (send(sock, echoString, echoStringLen, 0) != echoStringLen) printf("send() sent a different number of bytes than expected"); HWND hWinAmp = get_winamp_handle( ); //error checking... d79 4 a82 2 if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0) printf("recv() failed or connection closed prematurely"); d89 1 a89 1 SendMessage(hWinAmp,WM_WA_IPC,0,IPC_STARTPLAY); d92 1 a92 1 int res = SendMessage(hWinAmp,WM_WA_IPC,0,IPC_GETOUTPUTTIME); d96 1 a96 1 SendMessage(hWinAmp,WM_WA_IPC,atoi(echoBuffer)+100,IPC_JUMPTOTIME); d108 1 a108 1 exit(0); @ 1.3 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 105 a105 100 /* CHANGES FROM UNIX VERSION */ /* */ /* 1. Changed header files. */ /* 2. Added WSAStartUP() and WSACleanUp(). */ /* 3. Used closesocket() instead of close(). */ #include /* for printf(), fprintf() */ #include /* for socket(),... */ #include /* for exit() */ #include "blimpcli.h" #include "winamp.h" #define RCVBUFSIZE 32 /* Size of receive buffer */ HWND get_winamp_handle( void ) { HWND hwnd_winamp = FindWindow("Winamp v1.x",NULL); return hwnd_winamp; } int start_client( ) { int sock; /* Socket descriptor */ struct sockaddr_in echoServAddr; /* Echo server address */ unsigned short echoServPort; /* Echo server port */ char *servIP; /* Server IP address (dotted quad) */ char *echoString; /* String to send to echo server */ char echoBuffer[RCVBUFSIZE]; /* Buffer for echo string */ int echoStringLen; /* Length of string to echo */ int bytesRcvd, totalBytesRcvd; /* Bytes read in single recv() and total bytes read */ WSADATA wsaData; /* Structure for WinSock setup communication */ extern char *server_address; echoString = "running"; servIP = server_address; echoServPort = 32379; echoStringLen = strlen(echoString); if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) /* Load Winsock 2.0 DLL */ { fprintf(stderr, "WSAStartup() failed"); exit(1); } if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) printf("socket() failed"); memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */ echoServAddr.sin_family = AF_INET; /* Internet address family */ echoServAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */ echoServAddr.sin_port = htons(echoServPort); /* Server port */ if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) printf("connect() failed"); if (send(sock, echoString, echoStringLen, 0) != echoStringLen) printf("send() sent a different number of bytes than expected"); HWND hWinAmp = get_winamp_handle( ); //error checking... while( strcmp(echoBuffer,"quit") != 0 ){ echoStringLen = strlen(echoString); totalBytesRcvd = 0; while (totalBytesRcvd < 10) { if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0) printf("recv() failed or connection closed prematurely"); totalBytesRcvd += bytesRcvd; /* Keep tally of total bytes */ echoBuffer[bytesRcvd] = '\0'; /* Add \0 so printf knows where to stop */ } if( strcmp(echoBuffer,"IPC_STARTPLAY") == 0 ){ printf("I have been told to start playing winamp\n"); SendMessage(hWinAmp,WM_WA_IPC,0,IPC_STARTPLAY); } else{ printf("setting winamp to position: %s\n",echoBuffer); //get clients position and compare with server's(echoBuffer) //only jump-to-time if they're out of sync by x milliseconds SendMessage(hWinAmp,WM_WA_IPC,atoi(echoBuffer)+100,IPC_JUMPTOTIME); } }//while closesocket(sock); WSACleanup(); /* Cleanup Winsock */ exit(0); } @ 1.2 log @*** empty log message *** @ text @d36 1 a36 1 d38 1 a38 1 servIP = "10.5.0.165"; @ 1.1 log @Initial revision @ text @d74 2 a75 3 if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0) printf("recv() failed or connection closed prematurely"); d86 3 a88 1 SendMessage(hWinAmp,WM_WA_IPC,atoi(echoBuffer)+100,IPC_JUMPTOTIME); @ 1.1.1.1 log @Blimp Project @ text @@