|
Thanks for your assistance.
I added those lines to my project.
But, when I build the project, there was an error :
error C2065: 'ListenSocket' : undeclared identifier
So I added this line :
SOCKET ListenSocket;
Then I build it again, although I got some warning :
warning C4700: uninitialized local variable 'ListenSocket' used
there was no error.
Then I debug, try to connect from other computer.
It was connected, could read the buffer, but my program shows "0.0.0.0" as client's IP address.
Any suggestion?
----------
C++ Learner
|
|
|
|
|
Ok,
so you have used the CodeProject offered classes "Java-like-Sockets" without
knowing how it works.
The ListenSocket is a part of the source code that you need to etablish a connection.
You need to look into the SourceCode of the "Java-like-Sockets" Classes and check where
the accept(...) is performed. There you can add the line inet_ntoa(...); to get the Clients-IP-Address
If you have questions: i'll look here
Good luck
|
|
|
|
|
|
In sock.cpp you have the following lines :
SOCKET theClient;
SOCKADDR_IN clientAddr;
int ssz = sizeof(struct sockaddr);
theClient = accept(m_socket,(LPSOCKADDR)&clientAddr,&ssz);
if (theClient == INVALID_SOCKET) {
int nret = WSAGetLastError();
throw CSocketException(nret, "Invalid client socket: Accept()");
}
CSocket *sockClient = new CSocket();
sockClient->SetSocket(theClient);
sockClient->SetClientAddr(clientAddr);
m_socket is the socket which listens on the given Port. So m_socket is a ListenSocket
theClient is also a Socket which will store an Incomming-Connection from a Client.
clientAddr is a structure which will be filled with information during the accept()-function.
After accept was executing, you have the IP and Port into this strucure.
At the end you see that clientAddr is stored inside the class, so you can access from out
your source code, to the CServerSocket class and get the Client-Information-Structure.
You get the IP in plain text with
char TheClientIP[16]="";
strcpy(TheClientIP,inet_ntoa(...->sin_addr));
Good luck
|
|
|
|
|
Your response is always so fast.
I really appreciated your explanation about the source.
It's really easy to understand.
I think I got what it mean now.
But still doesn't know what is inside (...->sin_addr).
because m_clientAddr is an private object,
so I can't access it.
----------
C++ Learner
|
|
|
|
|
I solved it, thanks to your assistance.
Your answers really help me.
In main function, I added these lines :
CSocketAddress *addrs = sock->GetAddress();
ClientAddress = addrs->GetSockAddrIn();
buffer2 = inet_ntoa(ClientAddress.sin_addr);
Thanks again for your assistance.
-- modified at 12:15 Monday 10th September, 2007
----------
C++ Learner
|
|
|
|
|
Correct!
No problem for helping, i very glad that the hole CodeProject-Crew helps me with my problems LOL
Without the help of some guys here, i would be no more at my job
|
|
|
|
|
Hi all,
Actually i want to write a html file or .html page and i don't know how to do it using MFC. I know how to write a .txt file using CStdioFile class and using WriteString API's. Can any body tell me how to do it.
Thanks in advance
|
|
|
|
|
1. You must know the HTML tags.
2. While saving the file just specify the extension as .htm / .html.
And you are done with writing an .html file.
Regards,
Paresh.
|
|
|
|
|
|
Hi all
I ahev problem, I have code:
<br />
HANDLE hSearch = INVALID_HANDLE_VALUE; <br />
WIN32_FIND_DATA FileData; <br />
<br />
<br />
if(hSearch == INVALID_HANDLE_VALUE) <br />
hSearch = FindFirstFile("C:\\Myfolder\\Fi*",&FileData);
else<br />
FindNextFileA(Search,&FileData);<br />
<br />
when program go to "problem point" I get error message: NTDLL.dll
|
|
|
|
|
david bagaturia wrote: when program go to "problem point" I get error message: NTDLL.dll
NTDLL.dll ? That's a very descriptive error message
If you want some help, you have to provide at least some bit of usefull information. So, what happens exactly ? What does this message say exactly ?
|
|
|
|
|
I get this error: unhandled exception in cpy_file.exe (KERNEL32.dll):
0xE06D7363: Microsoft C++ Exception.
|
|
|
|
|
Use your debugger to inspect the variables and see exactly what happens.
|
|
|
|
|
My windows have some problems.
I restart My PC and now this code works good.
thanks for help.
|
|
|
|
|
Hi, I have two question.
First is how I can set bigger font to my list control, i get the font using
CFont* myFont = my_List.GetFont(); , can I use this font to enlarge it and than set it back?
And the second question is how to set background color to an a dialog?
Thanks!
|
|
|
|
|
josip cagalj wrote: how I can set bigger font to my list control,
You can create font object (member variable) and use SetFont() API of ListCtrl
josip cagalj wrote: how to set background color to an a dialog
Map the WM_CTLCOLOR and write,
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if( nCtlColor == CTLCOLOR_DLG )
{
hbr = (HBRUSH) GetStockObject( BLACK_BRUSH ); // or m_brushDlg.GetSafeHandle();
}
return hbr;
- NS -
|
|
|
|
|
Thanks for replay.
I do this:
<br />
CDC *pDC=GetDC();<br />
CFont VelikiFont;<br />
int nHeight;<br />
nHeight = -MulDiv(10, pDC->GetDeviceCaps(LOGPIXELSY), 72);<br />
VelikiFont.CreateFont(<br />
nHeight,
0,
0,
0,
FW_BOLD,
FALSE,
FALSE,
FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
FIXED_PITCH | FF_MODERN,
"Courier New"
);<br />
<br />
ReleaseDC(pDC);<br />
m_List.SetFont(&VelikiFont);
But I dont get what I wont. When I change 'nHeight' parameter I don't get bigger font, but more space between rows!
Regarding background color Can I set the color (like RGB value or something) instead of choosing type of stock object!
Once again thanks for replaying!
|
|
|
|
|
josip cagalj wrote: CFont VelikiFont;
Font object should be member or global. That is it should not be local.
josip cagalj wrote: Regarding background color Can I set the color (like RGB value or something) instead of choosing type of stock object!
In my sample I have placed a comment regarding this.
You have to keep a brush as member or global.
- NS -
|
|
|
|
|
How to put different text color only for one item?
I need this because I'll put different color on item text when mouse is over item!My list control has only one column.
Thanks
|
|
|
|
|
Hi
I want to Read data from the Folder and to write the same data in to another Folder.
I create the Folder as "CreateDirectory(L"c:\\mydirectory", NULL);"
Give your suggestion to Reading and Writing the data from Folder.
Regards
shakumar
-- modified at 7:26 Monday 10th September, 2007
shakumar
|
|
|
|
|
CFindFile will be useful
- NS -
|
|
|
|
|
shakumar_22 wrote: Give your suggestion to Reading and Writing the data from Folder.
There are a lot of ways, including STL streams, MFC classes such as CFile and CStdioFile , and the Win32 functions like Read() and Write() .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hi
I have code that will help
if you whont I will send you code
and comment.
|
|
|
|
|
Hello Friends,
Currently in free time i was just checking the C#.Net. and when I try to make the sample porject in C# in Visual Studio 2005 I amazed by the IntelliSense.It works so fast and nicely in C# but it doesnt working in the same manner when I am working on Win32 programming. Is there any way i can change the IntelliSense to work better.
|
|
|
|