I have a C++ client app that needs to communicate to a vb.net server application via a socket. I found some code that shows me how to create a c++ socket and send data.The connection seems to be working, just the sending of data is off.
On my vb.net server application i see that a connect was made but no data was ever sent. I tested my vb.net server application against a vb.net client application that talked on the same port and they were both communicating just fine. so i believe that my C++ send code is a miss somewhere i hope someone can point me in the right direction.
here is my c++ code.
i hope someone can point me out in the right direction.
cheers.
john
On my vb.net server application i see that a connect was made but no data was ever sent. I tested my vb.net server application against a vb.net client application that talked on the same port and they were both communicating just fine. so i believe that my C++ send code is a miss somewhere i hope someone can point me in the right direction.
here is my c++ code.
Code:
WORD version;
WSADATA wsaData;
int rVal=0;
version = MAKEWORD(1,1);
WSAStartup(version,(LPWSADATA)&wsaData);
LPHOSTENT hostEntry;
//store information about the server
hostEntry = gethostbyname("127.0.0.1");
if(!hostEntry)
{
sError("Failed gethostbyname()");
//WSACleanup();
return CS_ERROR;
}
//create the socket
SOCKET theSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(theSocket == SOCKET_ERROR)
{
sError("Failed socket()");
return CS_ERROR;
}
//Fill in the sockaddr_in struct
SOCKADDR_IN serverInfo;
serverInfo.sin_family = PF_INET;
serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
serverInfo.sin_port = htons(8888);
rVal=connect(theSocket,(LPSOCKADDR)&serverInfo, sizeof(serverInfo));
if(rVal==SOCKET_ERROR)
{
sError("Failed connect()");
return CS_ERROR;
}
//PROBLEM IN HERE?
char *buf = "simpleservermessage\n";
rVal = send(theSocket, buf, strlen(buf), 0);
if(rVal == SOCKET_ERROR)
{
sError("Failed send()");
return CS_ERROR;
}
closesocket(theSocket);
MessageBox(NULL, "Connection was made", "SOCKET", MB_OK);
WSACleanup();
return CS_OK;
i hope someone can point me out in the right direction.
cheers.
john