|
OK, but what is the expected behaviour and what is the problem you're complaing about?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
ptr_Electron wrote: I am getting expected string but it is not working as excepted...
This makes no sense.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
When i execute the code given below in C on Visual Studio 2008 i get the following error messages
1>------ Build started: Project: socketclientc, Configuration: Debug Win32 ------
1>Compiling...
1>client.c
1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(872) : see declaration of 'WSACleanup'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(69) : error C2059: syntax error : 'return'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(70) : error C2059: syntax error : '}'
1>Build log was saved at "file://c:\Documents and Settings\HP\My Documents\Visual Studio 2008\Projects\socketclientc\socketclientc\Debug\BuildLog.htm"
1>socketclientc - 25 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
// practiceclient.c : Defines the entry point for the console application.
#include <stdio.h>
#include <winsock2.h>
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;
}
|
|
|
|
|
Please check the posting guidelines before posting a message. Put your code inside code or pre tags and replace the < and > characters so that they can be visible. Furthermore, you selected only a part of the errors and you took the less relevant ones
Did you include winsock2.h ?
|
|
|
|
|
yea i used winsock2.h
and this program executes without problem in C++ but when i save the file as .c extension adn then i get so many errors do you want me to post my code again.
i need serrious help here
|
|
|
|
|
I would like to see which files you include and the complete errors that you have.
|
|
|
|
|
Thank you for reminding me to do that. Thanks a million i got it working all over again.
|
|
|
|
|
If you save the file with a .c extension, when then try to compile it, it will compile as a C file and not C++. So if you use any C++-specific constructs (which your code does), it will fail to compile.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
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
|
|
|
|
|
Yea thanks for tht but even after taking the variable declarations in the begining of the program i get error messages. For socket programming does C have some other constructs? Cos the books i used had socket as a structures and i could use it. can anyone suggest anything?
cheers
this is the error messages that i get.
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(11) : error C2065: 'sockaddr_in' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(11) : error C2146: syntax error : missing ';' before identifier 'Cservice'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(11) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(12) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(13) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(14) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(15) : error C2143: syntax error : missing ';' before 'type'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(33) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(33) : error C2224: left of '.sin_family' must have struct/union type
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(34) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(34) : error C2224: left of '.sin_addr' must have struct/union type
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(35) : error C2065: 'Cservice' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(35) : error C2224: left of '.sin_port' must have struct/union type
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(36) : error C2065: 'sockaddr' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(36) : error C2059: syntax error : ')'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(44) : error C2059: syntax error : 'while'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2065: 'mysocket' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2065: 'sendbuff' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4024: 'send' : different types for formal and actual parameter 2
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2065: 'sendbuff' : undeclared identifier
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : warning C4024: 'strlen' : different types for formal and actual parameter 1
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(58) : error C2099: initializer is not a constant
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(59) : error C2059: syntax error : 'if'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(61) : error C2059: syntax error : 'else'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(68) : warning C4273: 'getchar' : inconsistent dll linkage
1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(273) : see previous definition of 'getchar'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(69) : error C2373: 'WSACleanup' : redefinition; different type modifiers
1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2161) : see declaration of 'WSACleanup'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(70) : error C2059: syntax error : 'return'
1>c:\documents and settings\hp\my documents\visual studio 2008\projects\socketclientc\socketclientc\client.c(71) : error C2059: syntax error : '}'
1>Build log was saved at "file://c:\Documents and Settings\HP\My Documents\Visual Studio 2008\Projects\socketclientc\socketclientc\Debug\BuildLog.htm"
1>socketclientc - 25 error(s), 5 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|
|
|
|
Thank you for reminding and helping me out i got it all working now.
|
|
|
|
|
Hello Guru's
I am making a application in MFC ( Modal Dialog Based ) But its form size is constant as we have fixed at design time . Can any one told me how can make it Maximized automatic after clicking maximized box.
Regard's
Kaushik
|
|
|
|
|
Sorry, but I'm not sure I understood your problem correctly. Do you want that the controls on your dialog position themselves correctly when you maximize your dialog ?
If that's the case, then take a look at these articles[^]. The first one looks promising.
If it's not what you asked for, then explain your problem more clearly.
|
|
|
|
|
I mean to say
Suppose we have create a dialog box and put on it edit box check box
etc..
when we design form on 600x800 resolution monitor form see complete at monitor. But when we open it at different resolution its see small and if we maximize its half of part see blank. How can we programming so that all control adjust automatically.
Regard's
Kaushik
|
|
|
|
|
Did you look at the article I mentioned to you ?
|
|
|
|
|
SetWindowPos will help you to resize your control!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
ShowWindow(SW_MAXIMIZE)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
See the Extras sthis article.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
Try using ShowWindow(SW_MAXIMIZE).
thanks
Nitheesh
|
|
|
|
|
It seems you need to SetWindowPos or MoveWindow on the WM_SIZE.
|
|
|
|
|
Hello,
I would like to stop all messages to the window taskbar. I try to use the PreTranslateMessage function and it seems that the messages to the taskbar are not sending throw this function. Do you know a way to catch the messages?
Do you know if it should be throw this function?
Thank a lot !
|
|
|
|
|
TalSt wrote: I would like to stop all messages to the window taskbar. I try to use the PreTranslateMessage function and it seems that the messages to the taskbar are not sending throw this function. Do you know a way to catch the messages?
Use GetWindowLong and GWL_WNDPROC to get a window's main procedure address and replace it with your own version using SetWindowLong .
Now messages to the window which you hooked should go via your WindowProc . Store replaced WindowProc ptr to use with CallWindowProc to do default stuff. Don't forget to replace back this ptr when your application exits!
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Hello,
Can you give more details? I am not sure I understand...
How can the messages be stopped this way?
Thanks !
|
|
|
|
|
|
I assume by "window taskbar" you mean the taskbar with the "Start" button on it. This is part of "Explorer.exe". You can't expect to recieve messages from windows in another process via "PreTranslateMessage"!
Steve
|
|
|
|