<< SPLIT FROM socket connect returning odd >>
Code:#include<winsock.h> #include<stdio.h> #include<iostream.h> #include<windows.h> #include<conio.h> #include<string.h> /*Global data for sending and receiving using communication layer*/ WSADATA wsa_data; SOCKET Socket; SOCKET tempSocket; SOCKADDR_IN address; char data[50],ch; void comm_send(char ch[],int size); void comm_receive(); void comm_init(); void getInput(); void comm_close(); main(){ int index=0; comm_init(); cout<<"Receiving"<<endl; comm_receive(); if(!strcmp(data,"red")) cout<<"Stop"<<endl; else if(!strcmp(data,"green")) cout<<"Go"<<endl; else if(!strcmp(data,"yellow")) cout<<"Ready"<<endl; else if(!strcmp(data,"blue")) cout<<"Blocked"<<endl; else if(!strcmp(data,"orange")) cout<<"One way"<<endl; comm_close(); cout<<"Bye bye"; getch(); } /******************************************************/ void getInput(){ int index; do{ ch=getche(); data[index]=ch; index++; }while(ch!='\r'); data[index-1]='\0'; } /*-----------------------------------------------------*/ void comm_init(){ int result; result=WSAStartup(1.1,&wsa_data); Socket=socket(AF_INET,SOCK_STREAM,0); address.sin_port=50; address.sin_family=AF_INET; address.sin_addr.S_un.S_un_b.s_b1=127; address.sin_addr.S_un.S_un_b.s_b2=0; address.sin_addr.S_un.S_un_b.s_b3=0; address.sin_addr.S_un.S_un_b.s_b4=1; result=bind(Socket,(SOCKADDR *)&address,sizeof(address)); connect(Socket,(SOCKADDR *)&address,sizeof(address)); } void comm_send(char data[], int size){ int result; result=send(Socket,data,50,0); } void comm_close(){ closesocket(Socket); Socket=NULL; tempSocket=NULL; } void comm_receive(){ int result; listen(Socket,1); tempSocket=accept(Socket,NULL,NULL); cout<<"Connection established successfully"<<endl; Socket=tempSocket; //result=recv(Socket,data,50,0); do{ result=recv(Socket,data,50,0); cout<<"Data Received = "<<data<<endl; }while(result!=SOCKET_ERROR); }
this program srablishes connection itself with out server and ends.............what is the problemmmmm



LinkBack URL
About LinkBacks


