Problem with Socket
-
Hello, I am doing socket programming in VC++. I have two applications for Server and Client(in VC++). Message can be send/receive with these two applications from server to client or vice-versa. I download one HL7 Toolkit. I want to communicate this Toolkit with my applications. They did socket programming, but in Java. I want to know, can we send data if sender side socket is created in VC++ and on receiver side socket created in Java. Is socket programming is platform independent? Thanks in advance
-
Hello, I am doing socket programming in VC++. I have two applications for Server and Client(in VC++). Message can be send/receive with these two applications from server to client or vice-versa. I download one HL7 Toolkit. I want to communicate this Toolkit with my applications. They did socket programming, but in Java. I want to know, can we send data if sender side socket is created in VC++ and on receiver side socket created in Java. Is socket programming is platform independent? Thanks in advance
Yes socket programming is platform Independent.
Do not trust a computer... Always check what computer is doing regards, Divyang Mithaiwala Software Engineer
-
Hello, I am doing socket programming in VC++. I have two applications for Server and Client(in VC++). Message can be send/receive with these two applications from server to client or vice-versa. I download one HL7 Toolkit. I want to communicate this Toolkit with my applications. They did socket programming, but in Java. I want to know, can we send data if sender side socket is created in VC++ and on receiver side socket created in Java. Is socket programming is platform independent? Thanks in advance
-
Hello, I am doing socket programming in VC++. I have two applications for Server and Client(in VC++). Message can be send/receive with these two applications from server to client or vice-versa. I download one HL7 Toolkit. I want to communicate this Toolkit with my applications. They did socket programming, but in Java. I want to know, can we send data if sender side socket is created in VC++ and on receiver side socket created in Java. Is socket programming is platform independent? Thanks in advance
Yes, it is platform independent, but you need to take care below points when going across different platform (in terms of processer) 1) Before send data, convert your data in to network type. (ex. using "htonl" function.) 2) if you passing whole structure as a binary data then need to take care about padding. (use __attribute__((__packed__)))
Parag Patel Sr. Software Eng, Varaha Systems
-
Yes, it is platform independent, but you need to take care below points when going across different platform (in terms of processer) 1) Before send data, convert your data in to network type. (ex. using "htonl" function.) 2) if you passing whole structure as a binary data then need to take care about padding. (use __attribute__((__packed__)))
Parag Patel Sr. Software Eng, Varaha Systems
thanks. But now i can't send or receive the data from Toolkit which i download. My application is in VC++ and Toolkit is in Java. Is there any function i have to add in my application.
-
thanks. But now i can't send or receive the data from Toolkit which i download. My application is in VC++ and Toolkit is in Java. Is there any function i have to add in my application.
Abhijit D. Babar wrote:
But now i can't send or receive the data from Toolkit which i download. My application is in VC++ and Toolkit is in Java. Is there any function i have to add in my application.
is your toolkit is Socket server or socketclient. Are you connecting on right socket port?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
thanks. But now i can't send or receive the data from Toolkit which i download. My application is in VC++ and Toolkit is in Java. Is there any function i have to add in my application.
After running your application at both side (server/client) check that your application able to bind on that port or not? You can use "netstat" command in window.
Parag Patel Sr. Software Eng, Varaha Systems
-
After running your application at both side (server/client) check that your application able to bind on that port or not? You can use "netstat" command in window.
Parag Patel Sr. Software Eng, Varaha Systems
I use netstat and Telnet also and it bind the socket. But when i try to run my client program, it will wait or stop on "connect" function. I place the client code below, please see, where is the problem. /// Client code //// CString str; int sock,iResult,iOptVal,iSenderAddrSize; int BUFF_SIZE = 30,iError; char recv_data[30]; char* localIP = ""; struct sockaddr_in server_addr,SenderAddr; struct hostent * lpHostEntry; WSADATA wsaData; iSenderAddrSize = sizeof(SenderAddr); iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != NO_ERROR) AfxMessageBox(_T("Error at WSAStartup()\n")); if ((sock = socket(AF_INET, SOCK_STREAM,0)) == -1) AfxMessageBox(_T("Error at Socket")); gethostname(localIP,56); lpHostEntry = gethostbyname(localIP); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(2050); server_addr.sin_addr.s_addr = inet_addr("192.168.1.9"); iError = connect( sock, (SOCKADDR*) &server_addr, sizeof(server_addr) ); if(iError == SOCKET_ERROR){ iError = WSAGetLastError(); CString s1; s1.Format(_T("Connect Error = %d"),iError); AfxMessageBox(s1); exit(1); } while(1){ memset(recv_data,0,sizeof(recv_data)); int iResult = recv(sock,recv_data,BUFF_SIZE,0) ; if(iResult > 0) { recv_data[BUFF_SIZE] = '\0'; str = inet_ntoa(SenderAddr.sin_addr); AfxMessageBox(str); } else{ iError = WSAGetLastError(); } } //////// When i run my Server program, it will stop or wait on "accept" function. //// Server code ///// int sock, connected, bytes_recieved ; char send_data [1024] , recv_data[1024]; CString str,s; struct sockaddr_in server_addr,client_addr; int sin_size; int iResult; WSADATA wsaData; iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != NO_ERROR) AfxMessageBox(_T("Error at WSAStartup()\n")); if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { AfxMessageBox(_T("Socket")); exit(1); } server_addr.sin_family = AF_INET; server_addr.sin_port = htons(2050);
-
I use netstat and Telnet also and it bind the socket. But when i try to run my client program, it will wait or stop on "connect" function. I place the client code below, please see, where is the problem. /// Client code //// CString str; int sock,iResult,iOptVal,iSenderAddrSize; int BUFF_SIZE = 30,iError; char recv_data[30]; char* localIP = ""; struct sockaddr_in server_addr,SenderAddr; struct hostent * lpHostEntry; WSADATA wsaData; iSenderAddrSize = sizeof(SenderAddr); iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != NO_ERROR) AfxMessageBox(_T("Error at WSAStartup()\n")); if ((sock = socket(AF_INET, SOCK_STREAM,0)) == -1) AfxMessageBox(_T("Error at Socket")); gethostname(localIP,56); lpHostEntry = gethostbyname(localIP); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(2050); server_addr.sin_addr.s_addr = inet_addr("192.168.1.9"); iError = connect( sock, (SOCKADDR*) &server_addr, sizeof(server_addr) ); if(iError == SOCKET_ERROR){ iError = WSAGetLastError(); CString s1; s1.Format(_T("Connect Error = %d"),iError); AfxMessageBox(s1); exit(1); } while(1){ memset(recv_data,0,sizeof(recv_data)); int iResult = recv(sock,recv_data,BUFF_SIZE,0) ; if(iResult > 0) { recv_data[BUFF_SIZE] = '\0'; str = inet_ntoa(SenderAddr.sin_addr); AfxMessageBox(str); } else{ iError = WSAGetLastError(); } } //////// When i run my Server program, it will stop or wait on "accept" function. //// Server code ///// int sock, connected, bytes_recieved ; char send_data [1024] , recv_data[1024]; CString str,s; struct sockaddr_in server_addr,client_addr; int sin_size; int iResult; WSADATA wsaData; iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != NO_ERROR) AfxMessageBox(_T("Error at WSAStartup()\n")); if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { AfxMessageBox(_T("Socket")); exit(1); } server_addr.sin_family = AF_INET; server_addr.sin_port = htons(2050);
Hey man, code is working, i have tested it. I think something else in your application which is causing issue. Just cross check below basic things 1. Message box not going background, and thats why you are feeling that program is stuck. 2. You have given right IP at client side.
Parag Patel Sr. Software Eng, Varaha Systems