Coding Voice Chat Application Project

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Coding Voice Chat Application Project

only the coding...report will reach soon__________________________________________ ////////////////////////////UNDER DEVELOPMENT///////////////////////////////////////////////// ////////////Supporting voice as well as text chatting /////////////////////////////header files////////////////////////////////////////////////////// # include <windows.h> # include "resource.h" # include <process.h> # include <stdio.h> /////////////////////////////Macros//////////////////////////////////////////////////////////// #define BUFFER_SIZE 10000 #define SAMPLERATE 40025 #define APP_PORT1 214 #define APP_PORT2 428 #define WM_SOCKETREAD1 (WM_APP + 100) #define WM_SOCKETREAD2 (WM_APP + 101) ////////////////////////////////////////////////////////////////////////////////////////////// ///////////State which will be send by client after every one second static char USERSTATE[12]="IAMIN**IDLE"; SOCKADDR_IN saServer1,remote1,saServer2,remote2; SOCKET ssock1,csock1,ssock2,csock2; char CURRENTADDR[15]="192.168.0.255"; int threadclose=0; HINSTANCE hins; ////////these are four thread function//////////////////////////////////////////////////////// void recordthread(void *); void playthread(void *); void sendsignal(void *); void receivesignal(void *); ////////////////////////////////////////////////////////////////////////////////////////////// /* csock1- the client socket involved in chatting csock2- the client socket sending its state repeatedly

ssock1- the server socket involved in chatting ssock2- the server socket getting state info send by csock2 */ /////////////////////////////////////Global variables////////////////////////////////////////// char userlist[20][15];//array maintaining list of users int index=0; //index of last item in list char selfaddress[15]; char hostname[10]; HWND hwnd,hDlg1; PBYTE gRecordBuffer,gPlayBuffer; //int flag=0; //////////////////////////////////////Dialog procedures//////////////////////////////////////// void SetCurrentIP() { int nRetCode = gethostname ( CURRENTADDR, 256 ) ; if ( nRetCode != 0) { MessageBox (0,"Host name not available","VCA Application",MB_OK) ; return ; } hostent FAR *lpHostEnt = gethostbyname ( CURRENTADDR ) ; if ( lpHostEnt == NULL ) { MessageBox (0,"IPAddress not available","VCA Application",MB_OK); return; } LPSTR lpAddr = lpHostEnt -> h_addr_list[0] ; if ( lpAddr ) { in_addr inAddr ; memmove ( &inAddr, lpAddr, 4 ); char *chIP; chIP = inet_ntoa (inAddr) ; strcpy(CURRENTADDR,chIP); if(strlen(CURRENTADDR)==0) { MessageBox (0,"IPAddress not available","VCA

Application",MB_OK); } } } BOOL CALLBACK DialogProc(HWND hDlg, UINT MSG, WPARAM wParam, LPARAM lParam) { ///////////////Used In Recording and playing///////////////////////////////////////////////////////////// static int flag=0; static HWAVEIN hWaveIn; static HWAVEOUT hWaveOut; static PBYTE pBuffer1,pBuffer2,pBuffer3,pBuffer4,pBuffer5,pBuffer6; static PWAVEHDR pWaveHdr1,pWaveHdr2,pWaveHdr3,pWaveHdr4,pWaveHdr5,pWaveHdr6; static WAVEFORMATEX waveform,waveform1; ///////////////////Used In Text Chatting////////////////////////////////////////////////////// static HWND listhwnd,hwndstatic,hwndmessage,hwndcheck; //handle to list box containing list of users static HDC hdc,hdclist,hdcblink; static HBRUSH hbrushstatic; static HICON hicon; static char *str; static int pos,xm,ym; static char name[]={'C','H','A','T','T','I','N','G'}; hDlg1=hDlg; ///////////////////////////////////////////////////////////////////////// switch(MSG) { case WM_INITDIALOG: { //set current ip address SetCurrentIP(); ///////////////////Initializing Headers and buffers/////////////// pWaveHdr1=(PWAVEHDR)malloc(sizeof(WAVEHDR)); pWaveHdr2=(PWAVEHDR)malloc(sizeof(WAVEHDR)); pWaveHdr3=(PWAVEHDR)malloc(sizeof(WAVEHDR)); pWaveHdr4=(PWAVEHDR)malloc(sizeof(WAVEHDR));

pWaveHdr5=(PWAVEHDR)malloc(sizeof(WAVEHDR)); pWaveHdr6=(PWAVEHDR)malloc(sizeof(WAVEHDR)); MessageBox(NULL,"Start Recording ?","Record Info",0); gRecordBuffer=(PBYTE)malloc(BUFFER_SIZE); gPlayBuffer=(PBYTE)malloc(BUFFER_SIZE); pBuffer1=(PBYTE)malloc(BUFFER_SIZE); pBuffer2=(PBYTE)malloc(BUFFER_SIZE); pBuffer3=(PBYTE)malloc(BUFFER_SIZE); pBuffer4=(PBYTE)malloc(BUFFER_SIZE); pBuffer5=(PBYTE)malloc(BUFFER_SIZE); pBuffer6=(PBYTE)malloc(BUFFER_SIZE); if(!pBuffer1 || !pBuffer2 || !pBuffer3 || !pBuffer4 || !pBuffer5 || !pBuffer6) { if(pBuffer1) free (pBuffer1); if(pBuffer2) free (pBuffer2); if(pBuffer3) free (pBuffer3); if(pBuffer4) free (pBuffer4); if(pBuffer5) free (pBuffer5); if(pBuffer6) free (pBuffer6); MessageBeep(MB_ICONEXCLAMATION); MessageBox(hwnd,"Error in allocating memmory","Error info",0); return TRUE; } //open waveform fir input //defines the format of waveform-audio data waveform.wFormatTag =WAVE_FORMAT_PCM; //Waveform-audio format type waveform.nChannels =1;//Number of channels in the waveform-audio data waveform.nSamplesPerSec =SAMPLERATE;//Sample rate, in samples per second (hertz),

waveform.nAvgBytesPerSec =SAMPLERATE;//Required average data-transfer rate waveform.nBlockAlign =1; waveform.wBitsPerSample =16;//sample size 8 or 16 waveform.cbSize =0;//extra format information waveform1.wFormatTag =WAVE_FORMAT_PCM; //Waveform-audio format type waveform1.nChannels =1;//Number of channels in the waveform-audio data waveform1.nSamplesPerSec =SAMPLERATE;//Sample rate, in samples per second (hertz), waveform1.nAvgBytesPerSec =SAMPLERATE;//Required average data-transfer rate waveform1.nBlockAlign =1; waveform1.wBitsPerSample =16;//sample size 8 or 16 waveform1.cbSize =0;//extra format information /* if(waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)hDlg,0,CALLBACK_ WINDOW)) { free(pBuffer1); free(pBuffer2); free(pBuffer3); MessageBox(hwnd,"can't open for input","WARNING",MB_OK); }*/ pWaveHdr4->lpData =(LPSTR)pBuffer4; pWaveHdr4->dwBufferLength =BUFFER_SIZE; pWaveHdr4->dwBytesRecorded =0; pWaveHdr4->dwUser =0; pWaveHdr4->dwFlags =0; pWaveHdr4->dwLoops =0; pWaveHdr4->lpNext =NULL; pWaveHdr4->reserved =0; waveOutPrepareHeader(hWaveOut,pWaveHdr4,sizeof(WAVEHDR)); pWaveHdr5->lpData =(LPSTR)pBuffer5; pWaveHdr5->dwBufferLength =BUFFER_SIZE; pWaveHdr5->dwBytesRecorded =0; pWaveHdr5->dwUser =0;

pWaveHdr5->dwFlags =0; pWaveHdr5->dwLoops =0; pWaveHdr5->lpNext =NULL; pWaveHdr5->reserved =0; waveOutPrepareHeader(hWaveOut,pWaveHdr5,sizeof(WAVEHDR)); pWaveHdr6->lpData =(LPSTR)pBuffer6; pWaveHdr6->dwBufferLength =BUFFER_SIZE; pWaveHdr6->dwBytesRecorded =0; pWaveHdr6->dwUser =0; pWaveHdr6->dwFlags =0; pWaveHdr6->dwLoops =0; pWaveHdr6->lpNext =NULL; pWaveHdr6->reserved =0; waveOutPrepareHeader(hWaveOut,pWaveHdr6,sizeof(WAVEHDR));

//waveOutOpen(&hWaveOut,WAVE_MAPPER,&waveform1,(DWORD)hwnd,0,CALLBACK_ WINDOW); pWaveHdr1->lpData =(LPSTR)pBuffer1; pWaveHdr1->dwBufferLength =BUFFER_SIZE; pWaveHdr1->dwBytesRecorded =0; pWaveHdr1->dwUser =0; pWaveHdr1->dwFlags =0; pWaveHdr1->dwLoops =0; pWaveHdr1->lpNext =NULL; pWaveHdr1->reserved =0; waveInPrepareHeader(hWaveIn,pWaveHdr1,sizeof(WAVEHDR)); pWaveHdr2->lpData =(LPSTR)pBuffer2; pWaveHdr2->dwBufferLength =BUFFER_SIZE; pWaveHdr2->dwBytesRecorded =0; pWaveHdr2->dwUser =0; pWaveHdr2->dwFlags =0; pWaveHdr2->dwLoops =0; pWaveHdr2->lpNext =NULL; pWaveHdr2->reserved =0; waveInPrepareHeader(hWaveIn,pWaveHdr2,sizeof(WAVEHDR));

pWaveHdr3->lpData =(LPSTR)pBuffer3; pWaveHdr3->dwBufferLength =BUFFER_SIZE; pWaveHdr3->dwBytesRecorded =0; pWaveHdr3->dwUser =0; pWaveHdr3->dwFlags =0; pWaveHdr3->dwLoops =0; pWaveHdr3->lpNext =NULL; pWaveHdr3->reserved =0; waveInPrepareHeader(hWaveIn,pWaveHdr3,sizeof(WAVEHDR));

//////////////////////brush intialization/////////////////// hbrushstatic=CreateSolidBrush(RGB(150,90,250)); //notify whenever a socket event occur by sending specified message WSAAsyncSelect(ssock1, hDlg, WM_SOCKETREAD1, FD_READ); WSAAsyncSelect(ssock2, hDlg, WM_SOCKETREAD2, FD_READ); hwnd=GetDlgItem(hDlg,IDC_TEXT); hwndstatic=GetDlgItem(hDlg,IDC_TITLE); str=(char *)calloc(8,sizeof(char)); SendMessage(hwnd,BM_SETCHECK,1,0); hwnd=GetDlgItem(hDlg,IDC_BROADCAST); SendMessage(hwnd,BM_SETCHECK,1,0); listhwnd=GetDlgItem(hDlg,IDC_USERLIST); hwnd=GetDlgItem(hDlg,IDC_USERLIST); EnableWindow(hwnd,FALSE); hwnd=GetDlgItem(hDlg,IDC_CURRENT); EnableWindow(hwnd,FALSE); gethostname(hostname,10); sendto(csock2,hostname,strlen(hostname), 0, (SOCKADDR *)&remote2, sizeof(SOCKADDR)); //Broadcasting on network that new process has started sendto(csock2,"NEWCL**IN",strlen("NEWCL**IN"), 0, (SOCKADDR *)&remote2, sizeof(SOCKADDR));

SetClassLong(listhwnd,GCL_HBRBACKGROUND,RGB(56,111,120)); //starting timer to send state's info hicon=LoadIcon(hins,MAKEINTRESOURCE(IDI_ICON1)); SetClassLong(hDlg,GCL_HICON,(long)hicon); SetTimer(hDlg,1,1000,NULL); SetTimer(hDlg,2,100,NULL); } break; //////////////////////////////////////////////////////////////////////////////////////// case MM_WIM_OPEN: MessageBox(hwnd,"Input Device is opened","Device info",0); waveInAddBuffer(hWaveIn,pWaveHdr1,sizeof(WAVEHDR)); waveInAddBuffer(hWaveIn,pWaveHdr2,sizeof(WAVEHDR)); waveInAddBuffer(hWaveIn,pWaveHdr3,sizeof(WAVEHDR)); waveInStart(hWaveIn); MessageBox(hwnd,"Recording Started","Recording Info",0); return TRUE; case MM_WOM_OPEN: //MessageBox(NULL,"Output Device is opened","Recording Info",0); waveOutPrepareHeader(hWaveOut,pWaveHdr4,sizeof(WAVEHDR)); waveOutWrite(hWaveOut,pWaveHdr4,sizeof(WAVEHDR)); waveOutPrepareHeader(hWaveOut,pWaveHdr5,sizeof(WAVEHDR)); waveOutWrite(hWaveOut,pWaveHdr5,sizeof(WAVEHDR)); waveOutPrepareHeader(hWaveOut,pWaveHdr6,sizeof(WAVEHDR)); waveOutWrite(hWaveOut,pWaveHdr6,sizeof(WAVEHDR)); return TRUE; case MM_WIM_DATA:

//CopyMemory(gRecordBuffer,((PWAVEHDR)lParam)->lpData,BUFFER_SIZE); //remote1.sin_addr.s_addr = inet_addr("192.168.0.40"); sendto(csock1,((PWAVEHDR)lParam)->lpData,BUFFER_SIZE,0,(SOCKADDR *)&remote1,sizeof(SOCKADDR)); //remote1.sin_addr.s_addr = inet_addr("192.168.0.255"); waveInAddBuffer(hWaveIn,(PWAVEHDR)lParam,sizeof(WAVEHDR)); return TRUE; case MM_WOM_DONE: CopyMemory(((PWAVEHDR)lParam)->lpData,gPlayBuffer,BUFFER_SIZE); waveOutPrepareHeader(hWaveOut,((PWAVEHDR)lParam),sizeof(WAVEHDR)); waveOutWrite(hWaveOut,((PWAVEHDR)lParam),sizeof(WAVEHDR)); return TRUE; case MM_WIM_CLOSE: waveInUnprepareHeader(hWaveIn,pWaveHdr1,sizeof(WAVEHDR)); waveInUnprepareHeader(hWaveIn,pWaveHdr2,sizeof(WAVEHDR)); waveInUnprepareHeader(hWaveIn,pWaveHdr3,sizeof(WAVEHDR)); waveInUnprepareHeader(hWaveIn,pWaveHdr4,sizeof(WAVEHDR)); waveInUnprepareHeader(hWaveIn,pWaveHdr5,sizeof(WAVEHDR)); waveInUnprepareHeader(hWaveIn,pWaveHdr6,sizeof(WAVEHDR)); free(pBuffer1); free(pBuffer2); free(pBuffer3); free(pBuffer4); free(pBuffer5); free(pBuffer6); return TRUE; ///////////////////////////////////////////////////////////////////////////

case WM_CTLCOLORSTATIC: SetTextColor(HDC(wParam),RGB(255,255,255)); SetBkMode((HDC)wParam,TRANSPARENT); if(hwndstatic==(HWND)lParam) { TextOut((HDC)wParam,200,0,"hello",5); } return (LRESULT)hbrushstatic; break; case WM_CTLCOLORLISTBOX: if(listhwnd==(HWND)lParam) { SetTextColor(HDC(wParam),RGB(128,0,0)); SetBkMode((HDC)wParam,TRANSPARENT); } else { SetTextColor(HDC(wParam),RGB(0,0,0)); SetBkMode((HDC)wParam,TRANSPARENT); } return (LRESULT)CreateSolidBrush(RGB(255,240,200)); break; case WM_CTLCOLORBTN: { SetTextColor(HDC(wParam),RGB(255,255,255)); SetBkMode((HDC)wParam,TRANSPARENT); return (LRESULT)CreateSolidBrush(RGB(255,240,200)); } break; case WM_PAINT: RECT rt; HBRUSH hbrush; hbrush=CreateSolidBrush(RGB(150,90,250)); GetClientRect(hDlg,&rt); hdc=GetDC(hDlg); SelectObject(hdc,hbrush); FillRect(hdc,&rt,hbrush); SetTextColor(hdc,RGB(255,0,0)); SetBkColor(hdc,RGB(0,255,0)); ReleaseDC(hDlg,hdc); hdc=GetDC(hwndstatic); TextOut(hdc,200,0,"hello",5); ReleaseDC(hwndstatic,hdc); break;

case WM_CLOSE: EndDialog(hDlg,0); break; case WM_COMMAND: { switch(wParam) { case IDC_VOICE: /*if(waveInOpen(&hWaveIn,WAVE_MAPPER,&waveform,(DWORD)hDlg,0,CALLBACK_W INDOW)) { free(pBuffer1); free(pBuffer2); free(pBuffer3); MessageBox(hwnd,"can't open for input","WARNING",MB_OK); }*/ hwnd=GetDlgItem(hDlg,IDC_MESSAGE_RECEIVE); EnableWindow(hwnd,FALSE); hwnd=GetDlgItem(hDlg,IDC_MESSAGE_SEND); EnableWindow(hwnd,FALSE); hwnd=GetDlgItem(hDlg,IDC_SEND); EnableWindow(hwnd,FALSE); return TRUE; case IDC_TEXT: hwnd=GetDlgItem(hDlg,IDC_MESSAGE_RECEIVE); EnableWindow(hwnd,TRUE); hwnd=GetDlgItem(hDlg,IDC_MESSAGE_SEND); EnableWindow(hwnd,TRUE); hwnd=GetDlgItem(hDlg,IDC_SEND); EnableWindow(hwnd,TRUE); return TRUE; case IDC_BROADCAST: strcpy(CURRENTADDR,"192.168.0.255"); hwnd=GetDlgItem(hDlg,IDC_USERLIST); EnableWindow(hwnd,FALSE); hwnd=GetDlgItem(hDlg,IDC_CURRENT); EnableWindow(hwnd,FALSE); //MessageBox(NULL,"dfsdfsF","asfadsa",0); return TRUE; case IDC_PERSONAL: { SendMessage(listhwnd,LB_SETCURSEL,0,0);

int idx=SendMessage(listhwnd,LB_GETCURSEL,0,0); SendMessage(listhwnd,LB_GETTEXT,idx,(LPARAM)CURRENTADDR); remote1.sin_addr.s_addr = inet_addr(CURRENTADDR); hwnd=GetDlgItem(hDlg,IDC_USERLIST); EnableWindow(hwnd,TRUE); hwnd=GetDlgItem(hDlg,IDC_CURRENT); EnableWindow(hwnd,TRUE); if(strcmp(CURRENTADDR,"192.168.0.255")!=0&&strcmp(CURRENTADDR,"")!=0) SetDlgItemText(hDlg,IDC_CURRENT,CURRENTADDR); return TRUE; } case IDC_SEND: { char str[15]; GetDlgItemText(hDlg,IDC_CURRENT,str,15); hwnd=GetDlgItem(hDlg,IDC_PERSONAL); int icheck1=SendMessage(hwnd,BM_GETCHECK,0,0); if(strcmp(str,"")==0 && icheck1) { MessageBox(NULL,"Please connect before sending","WARNING",0); return TRUE; } char buffer[256]; //getting the text to be send GetDlgItemText(hDlg, IDC_MESSAGE_SEND, buffer, 256); hwnd=GetDlgItem(hDlg,IDC_MESSAGE_RECEIVE); if(SendMessage(hwnd,LB_GETCOUNT,0,0)==15) SendMessage(hwnd,LB_DELETESTRING,0,0); SendMessage(hwnd,LB_ADDSTRING,0,(LPARAM)buffer); int len = sizeof(SOCKADDR); //sending to socket ssock1 sendto(csock1, buffer, strlen(buffer), 0, (SOCKADDR *)&remote1, sizeof(SOCKADDR)); } break; case IDC_CONNECT: { threadclose=1;

//getting the selected ipaddress int idx=SendMessage(listhwnd,LB_GETCURSEL,0,0); SendMessage(listhwnd,LB_GETTEXT,idx,(LPARAM)CURRENTADDR); SetDlgItemText(hDlg,IDC_CURRENT,CURRENTADDR); //setting the ip address to the selected address from the list remote1.sin_addr.s_addr = inet_addr(CURRENTADDR); strcpy(USERSTATE,"IAMIN**BUSY"); InvalidateRect(listhwnd,NULL,FALSE); hwnd=GetDlgItem(hDlg,IDC_TEXT); int icheck=SendMessage(hwnd,BM_GETCHECK,0,0); hwnd=GetDlgItem(hDlg,IDC_BROADCAST); int icheck1=SendMessage(hwnd,BM_GETCHECK,0,0); if(icheck==0&&icheck1==0) { _beginthread(recordthread,0,NULL); } break; } case IDC_CLOSECONNECTION: strcpy(USERSTATE,"IAMIN**IDLE"); //resetting the ipaddress to broadcast address SetDlgItemText(hDlg,IDC_CURRENT,""); remote1.sin_addr.s_addr inet_addr("192.168.0.255"); break; case IDC_CANCEL: //ReleaseDC(listhwnd,hdc); //broadcasting of its exit so that others canupdate their list sendto(csock2,"NEWCL**OUT",strlen("NEWCL**OUT"), 0, (SOCKADDR *)&remote2, sizeof(SOCKADDR)); KillTimer(hDlg,1); //KillTimer(hwndstatic,2); EndDialog(hDlg, 0); break; } } break; case WM_TIMER: //broadcasting its state switch(wParam) { case 1:

sendto(csock2,USERSTATE,strlen(USERSTATE), 0, (SOCKADDR *)&remote2, sizeof(SOCKADDR)); break; case 2: //InvalidateRect(hwndstatic,NULL,TRUE); strcpy(str,""); for(int j=0;j<=pos;j++) sprintf(str,"%s%c",str,name[j]); hdcblink=GetWindowDC(hDlg); SetWindowText(hDlg,str); ReleaseDC(hwnd,hdcblink); pos++; if(pos>7) pos=pos*0; xm++; ym++; break; } break; case WM_SOCKETREAD1: { char ipaddress[15]; hwndcheck=GetDlgItem(hDlg,IDC_VOICE); int icheck=SendMessage(hwndcheck,BM_GETCHECK,0,0); if(icheck==0) { SOCKADDR_IN from; char buffer[256]; int len = sizeof(SOCKADDR); memset(buffer, '\0', 256); //Receaving from csock1 recvfrom(ssock1, buffer, 256, 0,(SOCKADDR*)&from, &len); strcpy(ipaddress,inet_ntoa(from.sin_addr)); //setting the text to selected //SetDlgItemText(hDlg, IDC_MESSAGE_RECEIVE, buffer); //MessageBox(NULL,selfaddress,"",0); if(strcmp(ipaddress,selfaddress)!=0) { hwnd=GetDlgItem(hDlg,IDC_MESSAGE_RECEIVE);

if(SendMessage(hwnd,LB_GETCOUNT,0,0)==15) SendMessage(hwnd,LB_DELETESTRING,0,0); SendMessage(hwnd,LB_ADDSTRING,0,(LPARAM)buffer); } } else { SOCKADDR from; char * pBuffer; pBuffer=(char*)malloc(BUFFER_SIZE); int len = sizeof(SOCKADDR); int size=recvfrom(ssock1,pBuffer,BUFFER_SIZE,0,&from,&len); CopyMemory(gPlayBuffer,pBuffer,BUFFER_SIZE); if(flag==0) { CopyMemory(pBuffer4,gPlayBuffer,BUFFER_SIZE); //MessageBox(NULL,"Flag is 0","In Receive",0); } if(flag==1) CopyMemory(pBuffer5,gPlayBuffer,BUFFER_SIZE); if(flag==2) { CopyMemory(pBuffer6,gPlayBuffer,BUFFER_SIZE); waveOutOpen(&hWaveOut,WAVE_MAPPER,&waveform1,(DWORD)hDlg,0,CALLBACK_ WINDOW); //MessageBox(NULL,"Opened for output","Out Info",0); } flag++; free(pBuffer); //for receiving voice signals //run thread for receiving voice sinal //_beginthread(playthread,0,NULL); } } break; case WM_SOCKETREAD2: {

SOCKADDR_IN from; char ipaddress[15]; char buffer[256]; int len = sizeof(SOCKADDR); memset(buffer, '\0', 256); //receaving state's info recvfrom(ssock2, buffer, 256, 0,(SOCKADDR*)&from, &len); strcpy(ipaddress,inet_ntoa(from.sin_addr)); if(strcmp("IAMIN**BUSY",buffer)==0) { //sendto(csock2,USERSTATE,strlen(USERSTATE), 0, (SOCKADDR *)&remote2, sizeof(SOCKADDR)); } else if(strcmp("IAMIN**IDLE",buffer)==0) { //strcmp(USERSTATE,"IAMIN**BUSY"); } //if a new user is in else if(strcmp("NEWCL**IN",buffer)==0) { //checking if the message is from the machine itself if(strcmp(ipaddress,selfaddress)!=0) { //updating its list SendMessage(listhwnd,LB_ADDSTRING,0,(LPARAM)ipaddress); //Replying back with its state remote2.sin_addr.s_addr inet_addr(ipaddress); sendto(csock2,"NEWCL**OK",strlen("NEWCL**OK"), 0, (SOCKADDR *)&remote2, sizeof(SOCKADDR)); //setting the ipaddress to broadcast address remote2.sin_addr.s_addr inet_addr("192.168.0.255"); } } else if(strcmp("NEWCL**OUT",buffer)==0) { for(int i=0;i<SendMessage(listhwnd,LB_GETCOUNT,0,0);i++) { char ch[16];

SendMessage(listhwnd,LB_GETTEXT,i,(LPARAM)ch); if(strcmp(ch,ipaddress)==0) { SendMessage(listhwnd,LB_DELETESTRING,i,0); } } } else if(strcmp("NEWCL**OK",buffer)==0) { SendMessage(listhwnd,LB_ADDSTRING,0,(LPARAM)ipaddress); } else if(strcmp(hostname,buffer)==0) { strcpy(selfaddress,inet_ntoa(from.sin_addr)); } } break; } return(0); } ///////////////////////////////////////WinMain Function//////////////////////////////////////////////// int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WSADATA data; if (WSAStartup(MAKEWORD(2,2), &data) != 0) return(0); int ret; hins=hInstance; ssock1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); ssock2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (!ssock1) { WSACleanup(); return(0); } saServer1.sin_family = AF_INET;

saServer1.sin_addr.s_addr = INADDR_ANY; saServer1.sin_port = htons(APP_PORT1); ret = bind(ssock1, (SOCKADDR *)&saServer1, sizeof(SOCKADDR)); saServer2.sin_family = AF_INET; saServer2.sin_addr.s_addr = INADDR_ANY; saServer2.sin_port = htons(APP_PORT2); ret = bind(ssock2, (SOCKADDR *)&saServer2, sizeof(SOCKADDR)); if (ret) { WSACleanup(); return(false); } csock1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); remote1.sin_family = AF_INET; remote1.sin_addr.s_addr = inet_addr(CURRENTADDR); remote1.sin_port = htons(APP_PORT1); csock2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); remote2.sin_family = AF_INET; remote2.sin_addr.s_addr = inet_addr("192.168.0.255"); remote2.sin_port = htons(APP_PORT2); DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc); closesocket(csock1); closesocket(ssock1); closesocket(csock2); closesocket(ssock2); WSACleanup(); return(1); } /////////////////////////////////////Function's Declaration///////////////////////////////////////////// void recordthread(void *args) { while(1) { //thread for recording voice //voice of client user hwnd=GetDlgItem(hDlg1,IDC_TEXT); int icheck=SendMessage(hwnd,BM_GETCHECK,0,0); if(icheck!=0||threadclose==1) _endthread(); } }

void playthread(void *args) { //thread for playing the //signals received from socket or remote user } void sendsignal(void *args) { //thread send signals //recording of client user } void receivesignal(void *args) { //thread receive signals from remote user //send for playing voice } ///////////////////////////////////////////////////////////////////////////////////////////////

You might also like