Click here to Skip to main content
15,920,704 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: add " to a string Pin
David Crow7-Apr-08 3:37
David Crow7-Apr-08 3:37 
Generalsocket proramming Pin
ADTC#6-Apr-08 22:34
ADTC#6-Apr-08 22:34 
GeneralRe: socket proramming Pin
Cedric Moonen6-Apr-08 23:08
Cedric Moonen6-Apr-08 23:08 
QuestionRe: socket proramming Pin
ADTC#7-Apr-08 1:50
ADTC#7-Apr-08 1:50 
GeneralRe: socket proramming Pin
Cedric Moonen7-Apr-08 3:04
Cedric Moonen7-Apr-08 3:04 
GeneralRe: socket proramming Pin
ADTC#7-Apr-08 20:31
ADTC#7-Apr-08 20:31 
GeneralRe: socket proramming Pin
James R. Twine7-Apr-08 3:44
James R. Twine7-Apr-08 3:44 
GeneralRe: socket proramming Pin
Nitheesh George7-Apr-08 4:46
Nitheesh George7-Apr-08 4:46 
Hi,

In C you are required to declare the variables at the beginning of the block. but this is not necessary in C++. In C++ u can declare the variable just before it is going to be used . But this will show as erorr in C. so in your code the following bold statements cause errors in C.


#include
#include

int main()
{
WSADATA wsadata;
WORD wVersion;
int wsaerr;
wVersion = MAKEWORD(2,2);
wsaerr = WSAStartup(wVersion, &wsadata);
if(wsaerr != 0)
{
printf("There is a DLL linker problem");
return 0 ;
}
else
printf("\nDLL working and compatible!!");
SOCKET mysocket;
mysocket = socket(AF_INET,SOCK_STREAM,0);
if(mysocket == SOCKET_ERROR)
{
printf("socket cannote be created error: %d",WSAGetLastError);
WSACleanup();
return 0;
}
printf("\nSocket created successfully");
sockaddr_in Cservice;
Cservice.sin_family = AF_INET;
Cservice.sin_addr.s_addr = inet_addr("127.0.0.1");
Cservice.sin_port = htons(55555);
if(connect(mysocket,(sockaddr *)&Cservice,sizeof(Cservice))== SOCKET_ERROR)
{
printf("Connect is unsuccessful, error:%d",WSAGetLastError);
WSACleanup();
getchar();
return 0;
}
int bytesent;
int byterecv=SOCKET_ERROR;
char sendbuff[200] = "Client:This is a test string from client.";
char recvbuff[200] = "";

while(byterecv == SOCKET_ERROR)
{
byterecv = recv(mysocket,recvbuff,strlen(recvbuff),0);
if(byterecv==0||byterecv==WSAECONNRESET)
printf("\nClient: Connection closed");
if(byterecv>0)
return 0;
else
{
printf("\nClient: recv() is OK");
printf("\nClient: The string received %s",recvbuff);
printf("\nClient: The bytes received %d",byterecv);
}
}
bytesent=send(mysocket,sendbuff,strlen(sendbuff),0);
if(bytesent == SOCKET_ERROR)
printf("\nClient: send() failed:%d",WSAGetLastError);
else
{
printf("\n Client: send() is OK");
printf("\n Client: The string sent %s",sendbuff);
printf("\n Client: The number of bytes sent %d",bytesent);
}

getchar();
WSACleanup();
return 0;
}

thanks

Nitheesh
GeneralRe: socket proramming Pin
ADTC#7-Apr-08 18:29
ADTC#7-Apr-08 18:29 
GeneralRe: socket proramming Pin
ADTC#7-Apr-08 20:31
ADTC#7-Apr-08 20:31 
QuestionHow to resize window automatic. Pin
Y_Kaushik6-Apr-08 21:35
Y_Kaushik6-Apr-08 21:35 
AnswerRe: How to resize window automatic. Pin
Cedric Moonen6-Apr-08 21:49
Cedric Moonen6-Apr-08 21:49 
GeneralRe: How to resize window automatic. Pin
Y_Kaushik6-Apr-08 22:51
Y_Kaushik6-Apr-08 22:51 
GeneralRe: How to resize window automatic. Pin
Cedric Moonen6-Apr-08 23:04
Cedric Moonen6-Apr-08 23:04 
GeneralRe: How to resize window automatic. Pin
ThatsAlok7-Apr-08 2:49
ThatsAlok7-Apr-08 2:49 
AnswerRe: How to resize window automatic. Pin
ThatsAlok6-Apr-08 22:41
ThatsAlok6-Apr-08 22:41 
AnswerRe: How to resize window automatic. Pin
David Crow7-Apr-08 3:56
David Crow7-Apr-08 3:56 
AnswerRe: How to resize window automatic. Pin
Nitheesh George7-Apr-08 5:41
Nitheesh George7-Apr-08 5:41 
AnswerRe: How to resize window automatic. Pin
Hamid_RT8-Apr-08 7:22
Hamid_RT8-Apr-08 7:22 
Generalvirtual BOOL PreTranslateMessage(MSG* pMsg); Pin
TalSt6-Apr-08 21:15
TalSt6-Apr-08 21:15 
GeneralRe: virtual BOOL PreTranslateMessage(MSG* pMsg); Pin
Nibu babu thomas6-Apr-08 21:35
Nibu babu thomas6-Apr-08 21:35 
GeneralRe: virtual BOOL PreTranslateMessage(MSG* pMsg); Pin
TalSt6-Apr-08 22:39
TalSt6-Apr-08 22:39 
GeneralRe: virtual BOOL PreTranslateMessage(MSG* pMsg); Pin
Nibu babu thomas6-Apr-08 22:51
Nibu babu thomas6-Apr-08 22:51 
GeneralRe: virtual BOOL PreTranslateMessage(MSG* pMsg); Pin
Stephen Hewitt7-Apr-08 15:31
Stephen Hewitt7-Apr-08 15:31 
Generaldeleting a empty folder from a specified path Pin
neha.agarwal276-Apr-08 20:58
neha.agarwal276-Apr-08 20:58 

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.