|
> and have a global vector with about 200 SOCKET varibles
I'm using a (single) linked list to store all incoming sockets. Since I'm object orientated this list is a member variable.
If it helps: I'm running a regular timer, which takes care that idle sockets or sockets which do not identify protocol within a timeout get kicked. Also I have a maximum value of sockets to allow to be served. Well, maximum socket depends highly on OS, e.g. Win9x can't handle a lot AFAIK (mh not sure how much?). Just some safty settings.
PS: Does someone knows a Unix port of CAsyncSocket?
|
|
|
|
|
Then I have to learn using linked lists!
But if I create dynamic SOCKET varibles??
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Sorry Rickard, didn't get it.
Perhaps you wanna have a look into existing source code (I do that all time to ste... umm learn). Ask Google or join some programmer channels on IRC. Hope it helps.
|
|
|
|
|
I mean:
SOCKET* MySocket = new SOCKET;
but, in an array of many SOCKET varibles!
Moak wrote:
Perhaps you wanna have a look into existing source code (I do that all time to ste... umm learn). Ask Google or join some programmer channels on IRC. Hope it helps.
I'm not using IRC!
And I have tried dig into a IRC server code but it is difficult to understand!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Which tag do I need to post C++ sourcecode, readable?
|
|
|
|
|
<pre>
-c
I don't care, and you can't make me.
|
|
|
|
|
Here a very short snip when using CAsyncSocket, shortened:
typedef CList<CSocketNode*, CSocketNode*> CSocketNodeList;
CSocketNodeList m_NodesList;
CCriticalSection m_NodesListAccess;
void CSocketServer::OnAccept(int nErrorCode)
{
ASSERT(!nErrorCode);
CSocketNode* pSocket = new CSocketNode(this);
if (Accept(*pSocket))
{
m_NodesListAccess.Lock();
m_NodesList.AddTail(pSocket);
m_NodesListAccess.Unlock();
} else {
delete pSocket;
return;
}
}
Removing dead sockets is then later done with...
m_NodesListAccess.Lock();
delete m_NodesList.GetAt(pos);
m_NodesList.RemoveAt(pos);
m_NodesListAccess.Unlock();
Hope it helps......
|
|
|
|
|
Hello,
Sorry for posting this a second time.
I'm using MFC dialog based app. In it I have two dialog boxes Dialog1 and Dialog2. There is a Combo Box in Dialog2 that I want to populate with integer values obtained from Dialog1.
I know that I must use ResetContent() and InsertString(). But what I don't know is how to use them from Dialog1. The ComboBox has a control variable in Dialog2 but when I call this in Dialog1 I get errors. (I have included the header files). The following explains what I want to do.
Dialog1.cpp
#include "Dialog2.h"
clear all contents from the Combo Box in Dialog2
while (number < 10)
{
...
if(some condition)
{
write whatever the 'number' value is to the
combo box in Dialog2
}
...
number++;
}
Does anyone know how I can do this or know of any document explaining this.
Thanks in advance,
Aoife
|
|
|
|
|
Could you tell us which Error you got !! Maybe then somebody can help you .
Cheers
Sonu
|
|
|
|
|
In Dialog2 the ComboBox public control variable is m_cCombo.
In Dialog1 when I call m_cCombo.ResetContent();
I get told
error C2065: 'm_cCombo' : undeclared identifier
error C2228: left of '.ResetContent' must have class/struct/union type
In Dialog1.cpp I have included Dialog2.cpp
|
|
|
|
|
you must create an object of that class to use the combobox.
try this:
CDialog2 ob;
ob.m_cCombo.ResetContent();
Best Regards
Sonu
|
|
|
|
|
Thanks.
That has worked in that now I get no errors when I compile. But when It runs I get a debug assertion failure in File afxwin2.inl at this line (741)
{ ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0); }
Does this have something to do with the properties of the ComboBox?
Thanks for you help.
Aoife
|
|
|
|
|
check the resource id for the control and for the window...
Best Regards
Sonu
|
|
|
|
|
Hi!!
Is there any "good" open source messenger type application available in C++/MFC (except sonork). For sonork the source code of server is not available. So please inform me about any other you aware of. Actually i was given a task to design a messenger from scratch and i just want to take help of example code.
|
|
|
|
|
I am writing a database application in which I want to get the data from a table.I am getting the value of that field in other tables but couldnt get it from the table in which
32 filds are there.I am using MS Access database.Why i am not getting the same field from a big table?
I am opening the recordset like this.
RS->Open(CRecordset::snapshot,_T("[BO_RBM_LONG_DUR_CALLS]"),CRecordset::readOnly);
what is the problem?Please help me.
Thanks
Pathi
|
|
|
|
|
i need to create SDI frame work in Dll.
if any one have the way to it plz help me.
|
|
|
|
|
I was looking through the help for " _lfind " function but having trouble using it. Could anyone help please?
This is my situation
I have three CString Variables:
m_strEnterData, m_strFindData, m_DisplayResult
m_strEnterData has the input string.
m_strFindData has the string I am searching in m_strEnterData.
m_strDisplayResult is where I want to display the result
I saw the syntax for _lfind in the help but having trouble fitting it for my scenario. Can someone help ?
The reason, I was having m_strDisplayResult as CString is because I got to display a message back saying whether the data is found or not.
Thank you so much.
M
|
|
|
|
|
The scenario sounds like a simple (sub)string search... If so, I do not believe that ::_lfind(...) is what you will want to use.
For example, if you need to look for m_strFindData in m_strEnterData , then you could just do this:
int iWhere = m_strEnterData.Find( m_strFindData );<br />
<br />
if( iWhere != -1 )<br />
{<br />
m_strDisplayResult = _T( "Match Found!" );<br />
}<br />
else<br />
{<br />
m_strDisplayResult = _T( "Match NOT Found!" );<br />
}
Peace!
-=- James.
(Try Check Favorites Sometime!)
|
|
|
|
|
ok... "yes, this is a game" last one i prgrammed, though, wasnt a game "im just trying to learn
ive made a header file and called it drpgf.h for data rpg files.header
this is some of my code:
_____________________________________
struct Counters
{
char cname[100] //counters name
int chp // counters hit points
};
void Monsters()
{
Counters goblin =
{"goblin", //cname
25 // chp
};
}//end Monsters
____________________________________
now in my cpp file... how would i recall the info that i made in my header...
i want to do somthing like this:
_____________________________________
Monster()
cout << goblin.cname[100] << endl;
but it says that goblin doesnt exist...
i would post all my code,... but CP mutilates it
please help...
Thanks!
~SilverShalkin
ps... i guess i could check the "display this message as is (no HTML)
if you guys need more info.. ill just do that
|
|
|
|
|
SilverShalkin wrote:
ps... i guess i could check the "display this message as is (no HTML)
Yeah, there's a thought.....
SilverShalkin wrote:
void Monsters()
{
Counters goblin =
{"goblin", //cname
25 // chp
};
}//end Monsters
Of COURSE you can't access goblin in your cpp. It doesn't exist !!! If you call Monsters, then goblin will exist between you making the call and the next line. IF monsters is a function inside a class, then Counters needs to be a member variable. If monsters is a global function then you could make the variable static. Another approach is to use namespaces to safely make it global.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
I would like to clarify what Christian Graus said.
Because you declared and initialized your struct goblin inside of a function, the scope or visibility of the variable goblin is restricted to inside the function Monster. You can solve this problem by simply making the variable goblin a global variable, then it will be accessable from the global scope.
However the correct way to declare a global variable is to actually declare the variable in the cpp file, and redeclare a copy of the variable with the extern keyword in the header file, like this:
struct Counters
{
char cname[100]
int chp
};
extern Counters goblin;
Counters goblin =
{
"goblin",
25
};
This will prevent linker errors from occuring if you include the header file in more than one cpp module.
The only problem with declaring global variables is that they pollute the global namespace. If you are going to distrubute the modules that you write to other people then I would suggest that you include your variables and functions in a namespace. However if you are simply writing this code for yourself, then it is probably not necessary.
BTW, here is how you would put your global variable goblin in a namespace:
namespace drpgf
{
Counters goblin;
}
You can replace drpgf with any name that you would like.
If you want to access the goblin variable outside of the scope of the drpgf namespace, then you will have to reference it with the namespace operator (: like this:
drpgf::goblin.chp = 100;
One more thing, in order to format your code properly, you can put <PRE> and <'/PRE> tags around your code to format it the way that I have.
I hope this is helpful.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
So... i have to declare all my goblin stuff in my cpp? if so... that defeats thee intire purpose of using the header file,... except the structure.
how would i declare everything in my header and beable to recall it in my cpp file?
Thanks!
~SilverShalkin
|
|
|
|
|
You've missed the point totally. Can I say AGAIN that you need to wake up to yourself and accept that you are a beginner and should learn with beginner projects ?
I feel so uninspired to try to help you when you won't help yourself.
You can't see your goblin because it is local to a function. I dunno if the function is global or if it's part of a class, but a variable defined in a function is visible only in that function.
Like this:
header file
Goblin * TheRedGoblin;
class Foo
{
public:
Foo();'
~Foo();
int IAmTooStupidToLearnTheBasics();
void IWillNeverGetAnywhereAsAProgrammer();
Goblin * m_TheGreenGoblin;
}
cpp File:
Foo::Foo()
{
m_TheGreenGoblin = new Goblin();
TheRedGoblin = new Goblin(); // Terrible design, will only not leak memory if this class is a Singleton.
}
Foo::~Foo()
{
delete m_TheGreenGoblin;
}
int Foo::IAmTooStupidToLearnTheBasics()
{
Goblin * SomeOtherGoblin = new Goblin(); // this is a memory leak
return 768;
}
void Foo::IWillNeverGetAnywhereAsAProgrammer()
{
m_TheGreenGoblin->KillSomeone(); // Fine, it is a member variable
TheRedGoblin->KillSomeone(); // Fine, although a global variable is a bad idea
SomeOtherGolbin->KillSomeone(); // Compiler says what the hell are you talking about, there IS no 'SomeOtherGoblin, and there never was, unless you called
// IAmTooStupidToLearnTheBasics(), in which case it existed only within that function.
}
Do you get it now ? Please, PLEASE, wake up to the facts here. There is nothing wrong with being a beginner, and I'd love to help you, but because you refuse to take the time to learn this stuff properly, you will always suck and so will your games.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
I think that you may have a few good points that you are trying to convey to SilverShalkin but you are not doing it very tactfully and I sense a little bit of frustration or possibly hostility in your messages.
Are you trying to discourage him from trying to learn how to develop or do you think this is the best way to motivate him? I have no problem helping SilverShalkin, and he seems to only frustrate you, so if you just want to ignore his posts in the future I will make sure that his questions get answered.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Doesn't it frustrate you that this guy has *no* idea about absolute basics *AND* refuses to take the time to learn ? I've been helping him for weeks, I spent ages discussing possible beginner projects with him and it appears after all that he did not bother.
I guess I came across a little frustrated, that's because I am. I have no trouble with helping absolute beginners ( I was on fairly recently, after all ), but I can't understand why this guy refuses to learn the basic skills he needs before embarking on the sort of thing he seems to be attempting. I hope my post shocks him, it appears the only way left to try to encourage him to take the time to actually learn some C++ before he tries to write a game in it.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|