Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

socket send err.

Status
Not open for further replies.

jcisco2

Programmer
Apr 13, 2004
102
0
0
US
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.

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top