|
client && server versus client || server, good point. I hadn't thought on that much. I tend to go the separate route for simplicity but will consider more.
Thanks for taking the time to reply.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
btw, saw your issue with the IPAddressControl below
the difference between the IPAddressControl and the NetAddressCOntrol is, that the IPAddressControl will only handle IPV4 tcp/ip addresses, while the more complicated NetAddressControl will handle IPV4, IPV6 and DNS type addresses, BUT NEEDS TO BE TOLD which one its dealing with, with its 'SetAllowType' Method
Other than that, they should work almost the same - http://msdn.microsoft.com/en-us/library/bb399237.aspx[^]
'g'
|
|
|
|
|
Re IP versus NET, I had not recognized that difference, and it immediately explains much. I work in the arena of telemetry systems who are probably completely exclusive groups, meaning their systems are closed off from the public world. I will stick with the IP4 through the completion of this project, at least the first version, then see about re-visiting.
Thanks for recognizing that and taking the time to reply.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 9-Nov-14 12:10pm.
|
|
|
|
|
bkelly13 wrote: This is the first time I have considered using inheritance. Code efficiency overrides simplicity.
Is this the right way to go?
Should the core class be abstract? Or would that be getting a bit advanced for me.
Sure why not? ...if there is enough overlapping code that needs to be written, it makes sense to use a common base class, after all that's the point of inheritance.
If you want to see how somebody else has done something similar, check out the Practical Sockets[^] library. As a matter of fact, that library may already be doing what you're doing...
|
|
|
|
|
Thanks for the comment and the link.
I am doing this as self guided education and for use at work. The main app will start a function as a thread and that will instantiate the TCP class and start a method in the TCP/IP class to conduct all the I/O. That method will run until completion. The entire app is a high data rate telemetry system.
I have divided the send and receive into two separate paths, one to send and one to receive. Each path is a strict producer and consumer link. That tremendously reduces the complexity in communications between the main and the TCP thread. Its almost trivial.
At the lowest level, the TCP class starts a completion thread for the send side and soon will start another completion thread for the receive side.
All the TCP code is driven by events, no polling.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
bkelly13 wrote: At the lowest level, the TCP class starts a completion thread for the send side and soon will start another completion thread for the receive side.
I hope you're not literally starting a thread... that's actually a VERY slow process. If you have worker threads that do the same thing over and over again, it's best to start the threads once and leave them around until they're no longer required. You can use the thread pool concept if you need several worker threads instead of just one or two per IO.
Also, depending on the bandwidth, TCP/IP isn't the fastest thing in the world. I doubt telemetry can produce bandwidths high enough to cause a problem but if you start seeing backups, keep in mind that you're paying for the overhead involved in TCP/IP.
|
|
|
|
|
Yes, I mean start a thread. Clarification will be helpful. On start up the main app will create/instantiate the class that handles all the TCP/IP communications. That is separate thread from main. That class will create a separate thread just for the send completion events and another for the receive completion events. After all that is done, then the system is ready to process data. The threads all run until main app is shut down. There is no dynamic thread creation and destruction while moving data. This app uses overlapped I/O and completion events.
Why create two more threads? Because I discovered that a thread that did nothing but handle the send completion events would be rather simple. The breakout of that code from the TCP/IP class into the thread did much to simplify the TCP class that communicates with main and controls the details of the TCP/IP link. Then it was just a small step to do the same with the receive side.
TCP is the only method we have to transfer data between computers. Our display system only accepts data via TCP/IP. Our mission system is contained within a single room and the Ethernet bandwidth is 1Gbps. And for this particular link there is a dedicated port on the send and receive computers that carries nothing but the telemetry traffic.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
bkelly13 wrote: TCP is the only method we have to transfer data between computers. --------------------------. Our mission system is contained within a single room and the Ethernet bandwidth is 1Gbps.
Those statements are contradictory... the presence of Ethernet does not imply TCP/IP. There are different protocols that can be used over Ethernet (even raw Ethernet). Some, like TCP/IP, are built for error checking... some are built for speed.
bkelly13 wrote: Our display system only accepts data via TCP/IP.
Typically a GUI display and any other processing are completely independent of one another.
|
|
|
|
|
I stand corrected. The display system is provided by Symvionics and it only accepts data via a TCP/IP connection.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
In my client and server classes never inherited a common base class. They just used some common components/classes like a socket class, whatever. Often its cleaner and more correct to use composition than inheritance. Over-generalization is usually a bad thing that should be resolved later. I refer with this to the "Core" base class here. I guess "Core" here means a lot of things and you create an "is a" relationship with inheritance between Server and Core and between Client and Core, so basically your server "is a" set of a lot of things that means chaos. In case of simple programs its OK to have not so nice design but if you want to do it correctly then try to isolate components and features that can be correctly named and encapsulated into a class (like Socket). In my networked programs other components that often come to the scene are "Connection", "Channel", "Server-SideClientHandler" or whatever. So instead of inheriting from a common base class I think here its usually nicer to isolate common things into classes and just using those classes from both the server and the client. If I inherited from a common base class in this case than it would probably be a CApplication class or something similar in case of using a framework...
Another little note related to naming convention (although this is a matter of taste): When I have complex names like C_TCP_API_Server I usually remove parts of the name and use them as namespaces. For example in case of C_TCP_API_Server I would probably use a C_Server class that is inside a TCP_API namespace. This is however just style, its up to you how to name and organize things your code. I've already worked on codebases where the usage of namespaces was forbidden as part of the coding conventions.
/off
Fun fact: In my experience the most dangerous classes in object oriented code often have these names: Something-"Manager", Something-"System", Something-"Handler", Something-"Core", ...
/on
|
|
|
|
|
Hi, I wrote a program in Windows CE platform, CPU is ARM 427MHZ.
when program read a text file(size about 700KB,1000 lines) in Flash memory, it needs about 25 seconds to load the file.
is there a means to decrease the reading time?
file.Open(fileName,CFile::typeBinary | CFile::modeRead);
while ( UNReadString(&file,strLine) ) {
strLine.Trim();
strNum = strLine.Tokenize(TEXT("\t"),tokenPos);
strEng = strLine.Tokenize(TEXT("\t"),tokenPos); strCh = strLine.Tokenize(TEXT("\t"),tokenPos);
strRus = strLine.Tokenize(TEXT("\t"),tokenPos);
handleStr();
tokenPos = 0;
}
BOOL UNReadString(CFile *iFile, CString &strReturn)
{
TCHAR tc;
CString strBuff = _T("");
strReturn = _T("");
while( ( sizeof(TCHAR) ) == ( iFile->Read(&tc, sizeof(TCHAR))) ) {
strBuff = tc;
if(_T("\n") != strBuff) {
strReturn += strBuff;
}
else {
return TRUE; }
}
return FALSE;
}
modified 11-Nov-14 12:55pm.
|
|
|
|
|
econy wrote: file.Open(fileName,CFile::typeBinary | CFile::modeRead); Why do you open a textfile in binary mode? You will also find that your use of Trim and Tokenize on each line will add considerably to the time.
|
|
|
|
|
Since there are east asian words in the file, and I try to comment tokenize block, no update
|
|
|
|
|
What does UNReadString do, I cannot find a definition for it?
|
|
|
|
|
had added code for:
UNReadString(CFile *iFile, CString &strReturn)
|
|
|
|
|
Sorry, I was not clear; I meant that I could not find a definition for that function in MSDN, so I do not know what it does. Is this a standard part of WindowsCE and if so where is the documentation for it?
|
|
|
|
|
It is not a Wince or Windows function. I wrote it myself.
|
|
|
|
|
Then that may well be the place where all your time is being used up.
|
|
|
|
|
The first thing you've got to do is work out whether it's I/O bound or whether it's the data processing that's slowing things down. You might find that CFile isn't particularly well tuned for reading from flash and not buffering enough. If it turns out that it's the I/O that's causing the problem find the lowest level function you can call and see what the raw I/O speed of your device is for a range of buffer sizes and then implement something that hits the sweet spot in terms of buffer size. It's a shame you're using MFC classes and not standard library ones as it's a lot easier to replace the underlying buffering and I/O mechanism, but such is life!
Another thing might be to try reading more data in your while loop (say 512 characters at a time) and manually parcelling out the data rather than letting CFile::Read do it.
If it turns out that the I/O is fast enough then have a look at what you're doing with the data. If you've got a lot of string handling you might find loads of temporaries flying about (especially if you're using VC++ 2008 and earlier) and there's loads of hidden memory manipulation that's slowing things down. In that case look at reducing the number of temporaries you need by reusing objects and expoiting things like NRVO.
Anyway, the main thing though is to find out where the bottle neck is then do something about it.
|
|
|
|
|
I have written a program in c++ to check whether a number is prime or not.... I want to know if this is optimized or not..
#include<iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter a number:";
cin>>num;
if(num%6==1 || num%6==5 || num==2 || num==3)
{
cout<<"\n"<<num<<" is a prime number";
}
else
{
cout<<"\n"<<num<<" is not a prime number";
}
return 0;
}
Please help me out...
|
|
|
|
|
If you start programming, lesson number one : do not ask whether something is optimized or not without having performance target in mind.
People that ask you to optimize your code without reason just want to waste your time on trivia.
Takes 1 000 000 random numbers. Then measure how much times it takes to find out whether they are prime on your machine.
Then see if you can make it better with random changes and observe.
|
|
|
|
|
I want to know that this program is better than those which are solved using loops.....????
|
|
|
|
|
only way to know it is to do what I told you just above.
This not only depends on the code but on the compiler. A coder can't tell you without benchamrking.
|
|
|
|
|
"Optimized" is not the correct category here. It is simply wrong. 25%6=1, but 25 is not prime.
|
|
|
|
|
Windows 7, VS 2008, MFC, Dialog, c++
I would like to use a control of type Net Address control to provide a method for the user to enter an IP address. Here is the closest I can get:
void CTCP_Client_ConsumerDlg::OnBnClickedButton1()
{
NC_ADDRESS y;
PNC_ADDRESS a = &y;
a->pAddrInfo = 0;
a->PortNumber = 0;
a->PrefixLength = 0;
HRESULT x;
DWORD ip_address = 0;
x = c_net_work_address_edit_box.GetAddress( a );
ip_address = c_net_work_address_edit_box.GetAddress( a );
}
Item: c_net_work_address_edit_box was created by right clicking on the address control and creating a control variable. When I type in: 192.168.2.3 the expected value is not present.
Also: The edit box does not provide the dots between the four parts of the IP address. I have seen that used many places, but want to implement in my code now.
Edit: Answer: Look in section Dialog Editor of the dialog toolbox to find IP Address Control. I don't know what the Network Address Control is for but I lack sufficient knowledge to get it working for my needs.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 19-Oct-14 18:21pm.
|
|
|
|