Click here to Skip to main content
15,891,372 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to Get Event from Controls in Docking Dialog Pin
Sunil P V10-Jul-12 0:05
Sunil P V10-Jul-12 0:05 
QuestionWhy is pointer a compound type, not a fundamental type? Pin
sawerr7-Jul-12 22:06
sawerr7-Jul-12 22:06 
AnswerRe: Why is pointer a compound type, not a fundamental type? Pin
Richard MacCutchan7-Jul-12 23:20
mveRichard MacCutchan7-Jul-12 23:20 
AnswerRe: Why is pointer a compound type, not a fundamental type? Pin
«_Superman_»8-Jul-12 3:20
professional«_Superman_»8-Jul-12 3:20 
AnswerRe: Why is pointer a compound type, not a fundamental type? Pin
fat_boy8-Jul-12 4:03
fat_boy8-Jul-12 4:03 
QuestionHow to receive data using dynamic array in recv api()? Pin
vanithavadivel7-Jul-12 0:13
vanithavadivel7-Jul-12 0:13 
AnswerRe: How to receive data using dynamic array in recv api()? Pin
Richard MacCutchan7-Jul-12 0:55
mveRichard MacCutchan7-Jul-12 0:55 
AnswerRe: How to receive data using dynamic array in recv()? Pin
Software_Developer7-Jul-12 23:28
Software_Developer7-Jul-12 23:28 
Declare dynamic char buffer:
C#
char* Dynamic_Recieve_Buffer = new char[2000];

Use dynamic buffer:
C#
recv(mySocket , Dynamic_Receive_Buffer , 2000 , 0);



Example code:

C#
//*******************************
//	Dynamic receive buffer      *
//*******************************


#include<stdio.h>
#include<winsock2.h>

#pragma comment(lib,"ws2_32.lib") //Winsock Library



int main(int argc , char *argv[])
{

    char* Dynamic_Receive_Buffer = new char[2000];



	WSADATA wsa;
	SOCKET mySocket;
	struct sockaddr_in server;
	
	int recv_size;
    char *message;


	printf("\nInitialising Winsock...");
	if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
	{
		printf("Failed. Error Code : %d",WSAGetLastError());
		return 1;
	}
	
	printf("Initialised.\n");
	
	//Create a socket
	if((mySocket = socket(AF_INET , SOCK_STREAM , 0 )) == INVALID_SOCKET)
	{
		printf("Could not create socket : %d" , WSAGetLastError());
	}

	printf("Socket created.\n");
	
	
	server.sin_addr.s_addr = inet_addr("74.125.235.20");
	server.sin_family = AF_INET;
	server.sin_port = htons( 80 );

	//Connect to remote server
	if (connect(mySocket , (struct sockaddr *)&server , sizeof(server)) < 0)
	{
		puts("connect error");
		return 1;
	}
	
	puts("Connected");
	
	//Send some data
	message = "GET / HTTP/1.1\r\n\r\n";
	if( send(mySocket , message , strlen(message) , 0) < 0)
	{
		puts("Send failed");
		return 1;
	}
	puts("Data Send\n");
	
	//Receive a reply from the server
	if((recv_size = recv(mySocket , Dynamic_Receive_Buffer , 2000 , 0)) == SOCKET_ERROR)
	{
		puts("recv failed");
	}
	
	puts("Reply received\n");

	//Add a NULL terminating character to make it a proper string before printing
	Dynamic_Receive_Buffer[recv_size] = '\0';
	puts(Dynamic_Receive_Buffer);

	//delete [] Dynamic_Receive_Buffer;

	 

	return 0;
}

QuestionC programming question Pin
Kotiexalter6-Jul-12 18:05
Kotiexalter6-Jul-12 18:05 
AnswerRe: C programming question Pin
Richard MacCutchan6-Jul-12 21:09
mveRichard MacCutchan6-Jul-12 21:09 
AnswerRe: C programming question Pin
Code-o-mat6-Jul-12 22:45
Code-o-mat6-Jul-12 22:45 
GeneralRe: C programming question Pin
Richard MacCutchan7-Jul-12 0:48
mveRichard MacCutchan7-Jul-12 0:48 
GeneralRe: C programming question Pin
Code-o-mat7-Jul-12 9:04
Code-o-mat7-Jul-12 9:04 
GeneralRe: C programming question Pin
Richard Andrew x647-Jul-12 10:55
professionalRichard Andrew x647-Jul-12 10:55 
GeneralRe: C programming question Pin
BCN-1637-Jul-12 16:24
BCN-1637-Jul-12 16:24 
GeneralRe: C programming question Pin
Code-o-mat7-Jul-12 23:20
Code-o-mat7-Jul-12 23:20 
AnswerRe: C programming question Pin
CPallini8-Jul-12 9:45
mveCPallini8-Jul-12 9:45 
JokeRe: C programming question Pin
Albert Holguin8-Jul-12 17:12
professionalAlbert Holguin8-Jul-12 17:12 
QuestionSocket connection problem Pin
ForNow6-Jul-12 3:08
ForNow6-Jul-12 3:08 
AnswerRe: Socket connection problem Pin
Albert Holguin6-Jul-12 4:15
professionalAlbert Holguin6-Jul-12 4:15 
GeneralRe: Socket connection problem Pin
ForNow6-Jul-12 6:57
ForNow6-Jul-12 6:57 
AnswerRe: Socket connection problem Pin
fat_boy6-Jul-12 5:53
fat_boy6-Jul-12 5:53 
QuestionReading Buffer of unicode and ansi character Pin
john56326-Jul-12 0:06
john56326-Jul-12 0:06 
GeneralRe: Reading Buffer of unicode and ansi character Pin
Jochen Arndt6-Jul-12 0:22
professionalJochen Arndt6-Jul-12 0:22 
GeneralRe: Reading Buffer of unicode and ansi character Pin
john56326-Jul-12 0:39
john56326-Jul-12 0:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.