Click here to Skip to main content
11,435,048 members (48,593 online)

C / C++ / MFC

 
GeneralRe: What design to use? Pin
gourishsio9-Jul-12 19:10
membergourishsio9-Jul-12 19:10 
GeneralRe: What design to use? Pin
gourishsio10-Jul-12 19:14
membergourishsio10-Jul-12 19:14 
QuestionC programming question Pin
Kotiexalter8-Jul-12 18:50
memberKotiexalter8-Jul-12 18:50 
AnswerRe: C programming question Pin
«_Superman_»8-Jul-12 19:02
member«_Superman_»8-Jul-12 19:02 
AnswerRe: C programming question Pin
Madhan Mohan Reddy8-Jul-12 23:55
memberMadhan Mohan Reddy8-Jul-12 23:55 
QuestionHow to Get Event from Controls in Docking Dialog Pin
Member 21198448-Jul-12 2:27
memberMember 21198448-Jul-12 2:27 
AnswerRe: How to Get Event from Controls in Docking Dialog Pin
sunilkpv10-Jul-12 1:05
membersunilkpv10-Jul-12 1:05 
QuestionWhy is pointer a compound type, not a fundamental type? Pin
sawerr7-Jul-12 23:06
membersawerr7-Jul-12 23:06 
AnswerRe: Why is pointer a compound type, not a fundamental type? Pin
Richard MacCutchan8-Jul-12 0:20
mvpRichard MacCutchan8-Jul-12 0:20 
AnswerRe: Why is pointer a compound type, not a fundamental type? Pin
«_Superman_»8-Jul-12 4:20
member«_Superman_»8-Jul-12 4:20 
AnswerRe: Why is pointer a compound type, not a fundamental type? Pin
fat_boy8-Jul-12 5:03
memberfat_boy8-Jul-12 5:03 
QuestionHow to receive data using dynamic array in recv api()? Pin
vanithavadivel7-Jul-12 1:13
membervanithavadivel7-Jul-12 1:13 
AnswerRe: How to receive data using dynamic array in recv api()? Pin
Richard MacCutchan7-Jul-12 1:55
mvpRichard MacCutchan7-Jul-12 1:55 
AnswerRe: How to receive data using dynamic array in recv()? Pin
TopCoder238-Jul-12 0:28
memberTopCoder238-Jul-12 0:28 
Declare dynamic char buffer:
char* Dynamic_Recieve_Buffer = new char[2000];
Use dynamic buffer:
recv(mySocket , Dynamic_Receive_Buffer , 2000 , 0);


Example code:

//*******************************
//	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 19:05
memberKotiexalter6-Jul-12 19:05 
AnswerRe: C programming question Pin
Richard MacCutchan6-Jul-12 22:09
mvpRichard MacCutchan6-Jul-12 22:09 
AnswerRe: C programming question Pin
Code-o-mat6-Jul-12 23:45
memberCode-o-mat6-Jul-12 23:45 
GeneralRe: C programming question Pin
Richard MacCutchan7-Jul-12 1:48
mvpRichard MacCutchan7-Jul-12 1:48 
GeneralRe: C programming question Pin
Code-o-mat7-Jul-12 10:04
memberCode-o-mat7-Jul-12 10:04 
GeneralRe: C programming question Pin
Richard Andrew x647-Jul-12 11:55
memberRichard Andrew x647-Jul-12 11:55 
GeneralRe: C programming question Pin
BianChengNan7-Jul-12 17:24
memberBianChengNan7-Jul-12 17:24 
GeneralRe: C programming question Pin
Code-o-mat8-Jul-12 0:20
memberCode-o-mat8-Jul-12 0:20 
AnswerRe: C programming question Pin
CPallini8-Jul-12 10:45
mvpCPallini8-Jul-12 10:45 
JokeRe: C programming question Pin
Albert Holguin8-Jul-12 18:12
memberAlbert Holguin8-Jul-12 18:12 
QuestionSocket connection problem Pin
ForNow6-Jul-12 4:08
memberForNow6-Jul-12 4:08 
AnswerRe: Socket connection problem Pin
Albert Holguin6-Jul-12 5:15
memberAlbert Holguin6-Jul-12 5:15 
GeneralRe: Socket connection problem Pin
ForNow6-Jul-12 7:57
memberForNow6-Jul-12 7:57 
AnswerRe: Socket connection problem Pin
fat_boy6-Jul-12 6:53
memberfat_boy6-Jul-12 6:53 
QuestionReading Buffer of unicode and ansi character Pin
john56326-Jul-12 1:06
memberjohn56326-Jul-12 1:06 
GeneralRe: Reading Buffer of unicode and ansi character Pin
Jochen Arndt6-Jul-12 1:22
memberJochen Arndt6-Jul-12 1:22 
GeneralRe: Reading Buffer of unicode and ansi character Pin
john56326-Jul-12 1:39
memberjohn56326-Jul-12 1:39 
AnswerRe: Reading Buffer of unicode and ansi character Pin
Jochen Arndt6-Jul-12 1:56
memberJochen Arndt6-Jul-12 1:56 
GeneralRe: Reading Buffer of unicode and ansi character Pin
john56326-Jul-12 2:09
memberjohn56326-Jul-12 2:09 
GeneralRe: Reading Buffer of unicode and ansi character Pin
Jochen Arndt6-Jul-12 2:18
memberJochen Arndt6-Jul-12 2:18 
GeneralRe: Reading Buffer of unicode and ansi character Pin
john56326-Jul-12 2:31
memberjohn56326-Jul-12 2:31 
GeneralRe: Reading Buffer of unicode and ansi character Pin
Jochen Arndt6-Jul-12 2:52
memberJochen Arndt6-Jul-12 2:52 
GeneralRe: Reading Buffer of unicode and ansi character Pin
BianChengNan7-Jul-12 17:32
memberBianChengNan7-Jul-12 17:32 
GeneralRe: Reading Buffer of unicode and ansi character Pin
Jochen Arndt7-Jul-12 23:28
memberJochen Arndt7-Jul-12 23:28 
GeneralRe: Reading Buffer of unicode and ansi character Pin
BianChengNan8-Jul-12 3:36
memberBianChengNan8-Jul-12 3:36 
QuestionProgramming Problem Pin
Ahmed Charfeddine5-Jul-12 23:54
memberAhmed Charfeddine5-Jul-12 23:54 
GeneralRe: Programming Problem Pin
«_Superman_»6-Jul-12 18:55
member«_Superman_»6-Jul-12 18:55 
GeneralRe: Programming Problem Pin
Ahmed Charfeddine7-Jul-12 1:25
memberAhmed Charfeddine7-Jul-12 1:25 
QuestionFormat INT_MAX Pin
Flaviu25-Jul-12 23:53
memberFlaviu25-Jul-12 23:53 
AnswerRe: Format INT_MAX Pin
Jochen Arndt6-Jul-12 0:08
memberJochen Arndt6-Jul-12 0:08 
GeneralRe: Format INT_MAX Pin
Flaviu26-Jul-12 0:29
memberFlaviu26-Jul-12 0:29 
GeneralRe: Format INT_MAX Pin
DavidCrow6-Jul-12 3:38
memberDavidCrow6-Jul-12 3:38 
GeneralRe: Format INT_MAX Pin
Flaviu26-Jul-12 5:09
memberFlaviu26-Jul-12 5:09 
QuestionRe: Format INT_MAX Pin
DavidCrow6-Jul-12 5:41
memberDavidCrow6-Jul-12 5:41 
GeneralGet Client Area Excluding Scroll Bar Pin
AmbiguousName5-Jul-12 20:30
memberAmbiguousName5-Jul-12 20:30 
GeneralRe: Get Client Area Excluding Scroll Bar Pin
Jochen Arndt5-Jul-12 22:32
memberJochen Arndt5-Jul-12 22:32 

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

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


Advertise | Privacy | Mobile
Web04 | 2.8.150428.2 | Last Updated 5 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid