|
|
|
If you have a server listening on a particular port, the OS will automatically 'accept' all connections coming in on that port. There's no way (using BSD sockets anyway) to reject a particular connection; all you can do is close the socket() once you've accept()ed it. What are you trying to achieve? If you want to allow connections from a particular address only, then you can accept(), check the peer adddress, then close() the socket if it's not the connection you wish to accept.
If you're just trying to allow one connection in, denying all others after a successful connection, then you can close the listening socket after accept()ing.
If you really need to give a 'connection refused' message to a subset of people, you should consider using a firewall instead.
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
Matt Godbolt wrote: If you're just trying to allow one connection in, denying all others after a successful connection, then you can close the listening socket after accept()ing.
If you really need to give a 'connection refused' message to a subset of people, you should consider using a firewall instead.
I want to do the first thing you specified.
but want to display the message of second one.
SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
In that instance then, once you've accept()ed the first connection, you can close the socket you created to listen on. Any further connection attempts will be rejected with 'connection refused'. Something like:
SOCKET listenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
bind(listenSocket, localAddress);
listen(listenSocket, 1);
sockaddr_in connectingAddress;
int connectingAddressSize = sizeof(connectingAddress);
SOCKET incomingConnection = accept(listenSocket, &connectingAddress, &connectingAddressSize);
closesocket(listenSocket);
closesocket(incomingConnection);
NB this code is totally off the top of my head, so apologies if there's any compile issues, hopefully you get the idea!
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
Yea I was using this method. but this way could not convince me
anyway till I get another solution. this is my solution.
Thanks alot for your reply
SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
The Wireless adapters are to be disabled, if any wired interfaces are found and enabled if no wired interfaces are found or if the cable is disconnected.
This functionality shall work for any wireless adapters types like PCI, PCMCIA or USB interfaces.
|
|
|
|
|
Hi all,
I am using Visual studio 6.0. I need to read and store a .gif file in binary format in vc++.Please help me
thanks
vinod
vinsankar
-- modified at 7:31 Tuesday 4th July, 2006
|
|
|
|
|
is your source is a file?
sample code to read and write using CFIle.
CFile file;
if(file.Open("source.gif",CFile::modeRead|CFile::typeBinary))
int nLength = file.GetLength();
if(nLength >0)
{
byte* pBuffer = new byte[nLength];
file.Read(pBuffer,nLength);
CFile fileWrite;
if(fileWrite.Open("destination.gif",CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
fileWrite.Read(pBuffer,nLength);
fileWrite.Close();
}
file.Close();
}
SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
AFAIK you can read a file using the binary format
ifstream is( "myFile.gif", ios::binary );
char Data;
if( !is ) {
cerr << "Error opening file" << endl;
return false;
}
else
printf("file opened successfully");
while( is.read( (char*) &Data, sizeof(char) ) ) {
}
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
I have a byte array, which contains the data of a bitmap.
how can I set these information to a HIBITMAP?
I used SetBitmapBits function. But it's failed.
SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
|
I've been looking through some documentation recently but I couldn't find a way to make a shell extension managing the 'paste' message.
If you have a link to some helpful doc, I would be really grateful.
The goal is to manage the copies in a more advanced way,
like in this example :
http://supercopier.sfxteam.org/uploads/scdeplier.png
I've already done something like this in an old project of mine (a minimalistic file explorer), but this time I want it to be in Windows' file explorer.
Thanks in advance, and happy 4th of July to all Americans
|
|
|
|
|
Hi, All
I want to do this actions
My frame has spliter contains three view ( view 1, view 2, view 3)
when resize frame or scroll spliter i want to fix view 3, only resize view 1 or view 2.
please, tell me how to do this.
thank for reading.
.: Your success is also mine :.
|
|
|
|
|
Hi all,
From CDialog i have to Show a CFormView. How we can achieve this.
please help me out.
Uday.
|
|
|
|
|
Uday Janaswamy wrote: From CDialog i have to Show a CFormView. How we can achieve this.
What do you mean? Is your application dialog based, sdi or mdi?
|
|
|
|
|
hi chen,
i have to show a FormView from CDialog. By Default CDialog is Created by me by the wizard. then i derived a CFormView and respective Class for that view.
Now i have to show the Form View which i have created.
please let me know if you can.
thanks,
uday.
|
|
|
|
|
You can add one frame on dialog and create view with CFormView
same:
pMainFrame = (CFrameWnd*) RUNTIME_CLASS(CFrameWnd)->CreateObject();
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(128,
RUNTIME_CLASS(CDocument),
RUNTIME_CLASS(CFrameWnd),
RUNTIME_CLASS(CFormView));
CCreateContext sContext;
sContext.m_pCurrentDoc = (CDocument*) RUNTIME_CLASS(CDocument)->CreateObject();
sContext.m_pCurrentFrame = NULL;
sContext.m_pLastView = NULL;
sContext.m_pNewDocTemplate = pDocTemplate;
sContext.m_pNewViewClass = RUNTIME_CLASS(CFormView);
m_pMainFrame ->Create(strCssEditorClass, _T(""), WS_CHILD, CRect(0,0,1,1), this, NULL, 0, &sContext);
pMainFrame ->MoveWindow(0,0,200,200);
pMainFrame ->ShowWindow(SW_SHOW);
// OnInitDialog()
.: Your success is also mine :.
|
|
|
|
|
hi,
i am getting null value when i use the above code please help me out.
//================================================================
CFrameWnd *pMainFrame = (CFrameWnd*)RUNTIME_CLASS(kiranfrm)->CreateObject();
if(pMainFrame->m_hWnd == NULL)
{
//I am getting Null value here so i cant able to create a Handle.
}
//================================================================
Steps what i have done.
1) Create a Dialog and place a Button and in the Click even i pasted what you have mentioned.
2) Create a CForm and create CFormClass,CFormDoc Class,CFrameWnd Class.
//here is the Total Code please see it
CFrameWnd *pMainFrame = (CFrameWnd*)RUNTIME_CLASS(kiranfrm)->CreateObject();
if(pMainFrame->m_hWnd == NULL)
{
MessageBox("hellow");
return ;
}
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(128,
RUNTIME_CLASS(kirandoc),
RUNTIME_CLASS(kiranfrm),
RUNTIME_CLASS(kiran));
CCreateContext sContext;
sContext.m_pCurrentDoc = (CDocument*) RUNTIME_CLASS(kirandoc)->CreateObjec();
sContext.m_pCurrentFrame = NULL;
sContext.m_pLastView = NULL;
sContext.m_pNewDocTemplate = pDocTemplate;
sContext.m_pNewViewClass = RUNTIME_CLASS(kiran);
pMainFrame ->Create("", _T(""), WS_CHILD, CRect(0,0,1,1), this, NULL, 0, &sContext);
pMainFrame ->MoveWindow(0,0,200,200); //Error
pMainFrame ->ShowWindow(SW_SHOW); //Error
because m_hWnd is NULL.
-- modified at 9:09 Tuesday 4th July, 2006
|
|
|
|
|
Sorry !
you add this code
CString strClass= AfxRegisterWndClass(CS_VREDRAW|CS_HREDRAW, ::LoadCursor(NULL, IDC_ARROW), (HBRUSH)::GetStockObject(WHITE_BRUSH), ::LoadIcon(NULL, IDI_APPLICATION));
pMainFrame ->Create(strClass, _T(""), WS_CHILD, CRect(0,0,1,1), this, NULL, 0, &sContext);
pMainFrame ->MoveWindow(0,0,200,200);
pMainFrame ->ShowWindow(SW_SHOW);
Huynhnb
.: Your success is also mine :.
|
|
|
|
|
hi,
You are really great. Keep it up!!!!!!!!!!!!!.
uday.
|
|
|
|
|
Hi,
Every thing is Ok, But with this Code i am only able to see the Form View Embeded in the Dialog. Could you please provide me the solution for showing in different Window.
Here is the Code.
//========================================================================
void CMydlgDlg::OnButton1()
{
CFrameWnd *pMainFrame = (CFrameWnd*)RUNTIME_CLASS(kiranfrm)->CreateObject();
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(IDI_ICON1,
RUNTIME_CLASS(kirandoc),
RUNTIME_CLASS(kiranfrm),
RUNTIME_CLASS(kiran));
CCreateContext sContext;
sContext.m_pCurrentDoc = (CDocument*) RUNTIME_CLASS(kirandoc)->CreateObject();
sContext.m_pCurrentFrame = NULL;
sContext.m_pLastView = NULL;
sContext.m_pNewDocTemplate = pDocTemplate;
sContext.m_pNewViewClass = RUNTIME_CLASS(kiran);
CString strClass= AfxRegisterWndClass(CS_VREDRAW|CS_HREDRAW, ::LoadCursor(NULL, IDC_ARROW), (HBRUSH)::GetStockObject(WHITE_BRUSH), ::LoadIcon(NULL, IDI_APPLICATION));
pMainFrame ->Create(strClass, _T(""), WS_CHILD, CRect(0,0,1,1), this, NULL, 0, &sContext);
pMainFrame ->MoveWindow(200,100,300,300);
pMainFrame ->ShowWindow(SW_SHOW);
}
//========================================================================
Please help me out.
Uday
|
|
|
|
|
if you want to go from one dialog to CFormView see
CFrameWnd* pFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd;<br />
CPictureView* pView = (CPictureView *) pFrame->GetActiveView();
and use from pView->variables or functions
whitesky
|
|
|
|
|
Hello
I have a webcam and I want to get and save a snapshot from it to a .bmp file,do you know how can I do it?
thanks
|
|
|
|
|
DirectShow? You can have a look at the AMCap sample that comes with the SDK. You can just connect up the Capture filter -> Sample Grabber filter -> Null Renderer to get a bitmap from the Sample Grabber. There are various articles on DirectShow on CodeProject, just look them up.
|
|
|
|
|