|
Hello,
I'm coding two apps that swap data (client / server) over TCP/IP, SOCK_STREAM, using my derived classes from CSocket and CAsyncSocket. Data is stored in a custom struct (size 3k) known to both apps.
Code snippet:
---- sending data using CSocket
tagDATA data; // data to send, its a struct
// use my derived CSocket to send:
m_Socket.Send (&data, sizeof (tagDATA));
----- receiving data using CAsyncSocket
void CMyAsyncSocket::OnReceive(int nErrorCode)
{
tagDATA data;
CAsyncSocket::OnReceive(nErrorCode);
int iRcvd = Receive (&data, sizeof(tagDATA));
// process data here...
}
It all works fine when both programs are running on the same machine, however when transmitting data over the network each 3k data block is chopped into chunks of size (1460 * i) bytes. 1460 seems to be the ethernet frame size.
The problem is of course that I wont receive correct tagDATA objects (I dont get all data with the first call to Receive() ), but instead several chunks for each one send. Is this normal socket behaviour? Will I have to reassemble the received chunks "by hand"? SO_RCVBUF is set to 8k by default. I cannot find any hint about max buffer size in MFC's CAsyncSocket::Receive documentation.
I tested this behaviour with MS MFCSocs example - it seems to behave similar: When sending approx 8k the data gets chopped into two bits (3k and 5k).
Any help is greatly appreciated,
Steve
|
|
|
|
|
Welcome to the wild world of socket programming! This is the normal behaviour. What you need to do is copy the data in chunks to your buffer, keeping a running offset.
onwards and upwards...
|
|
|
|
|
Yes, thanks for your reply. I just completed coding this and it seems to work.
However I'm afraid this will mess up my communication sooner or later: For instance isnt't it possible that one chunk of data might get lost? Afterwards my offset will be invalid and I will interpret all following chunks incorrectly (putting them into the wrong offset into the buffer).
Of course I can reset the offset after a certain time (for instance I notice I only receive "crap") however I think this is more of a workaround than a solution, and all the data chunks from inbetween will be lost too.
Regards,
Steve
|
|
|
|
|
The job of the TCP part of the TCP/IP stack is to resequence the packets in the correct order for you. So, unless you are using very low level socket calls (which I would doubt), you don't have to worry about that.
onwards and upwards...
|
|
|
|
|
|
stevedoulg900 wrote:
For instance isnt't it possible that one chunk of data might get lost?
Yes, if you are using UDP. TCP, however, uses a retransmission strategy to insure that data will not be lost in transmission.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Using Visual C++ 6.0...
Can someone point me to a sample of putting a splitter into a CView-derived class.
I'm working on a SDI app that supports multiple views, and one of these views needs to contain a splitter.
I've tried a couple of things but can't get the split views to show up in the splitterwnd in the view.
------- sig starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
"You won't like me when I'm angry..." - Dr. Bruce Banner
Please review the Legal Disclaimer in my bio.
------- sig ends
|
|
|
|
|
Put a CSplitterWnd member variable in the parent frame, usually CMainFrm . Override the parent frame’s CFrameWnd::OnCreateClient() member function. From within the overridden OnCreateClient() , call the Create() or CreateStatic() member function of CSplitterWnd . There are several examples of this on both CP and MSDN.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Rather than creating the CView, create a CSplitterWnd.
onwards and upwards...
|
|
|
|
|
Nevermind - I got it.
I had neglected to override OnSize in the parent view.
------- sig starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
"You won't like me when I'm angry..." - Dr. Bruce Banner
Please review the Legal Disclaimer in my bio.
------- sig ends
|
|
|
|
|
Hi all,
im getting the following warning message on the below code,
now it seems to work ok, apart from this warning message i get when
i compile
does anyone have any idea's how i can get rid of it
Thanks
Si
warning C4267: '+=' : conversion from 'size_t' to 'int', possible loss of data
void MyFunc::Concat(LPTSTR strDest, LPCTSTR strSrc, int* pnInt)
{
memcpy(strDest+*pnInt, strSrc, _tcslen(strSrc)+1);
*pnInt += _tcslen(strSrc)+1;
}
|
|
|
|
|
_tcslen returns a size_t which I think is an unsigned int. All you need to do is change pnInt to a size_t* or an unsigned int*.
Mike
|
|
|
|
|
Hi
I am doing large application So i want to devlope my Resources like Dialog,Icons,Bitmap in .Dll and call from .exe .
So can anyone give me good example link ?
|
|
|
|
|
no need for the link do the following.
Put all the dll, menu, icons etc in the resrouce only dll,
in the initinstance of your mfc application Load the resource dll using
hRes = LoadLibrary(....);
if(hRes)
AfxSetResourceHandle(hRes);
This will make your dll resource same as ur exe resource. You can use
loadicon, loadmenu etc without passing the resouce handle.
When you want to get the resource handle
AfxGetResourceHandle();
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
hi friend ,
i see ur response but when i have try to load modeless dialog from dll it was just get onece blink and then disapper so what should i do for that .. and plz can u send me any example of this sort of dll which loads the dialog and bmp from dll.. if u send me than it's very easy for me..
and can u tell me what should i do for learning more and more abt dll.. because currently my project becomes very big.. so i wanna convert it into dll so that i can get speed..
thanks ..
once again..
and plz give me respose as soon as possible along with example.....
|
|
|
|
|
Was, by any chance, your modeless dialog done like this?
SomeFunctionOrOther()
{
CMyModeless dialog;
dialog.Create(...);
}
If so, then it's nothing to do with DLLs or anything as complicated, it's more to do with the fact that modeless dialogs cannot be done that way.
You'd need
CMyModeless* dialog;
dialog = new CMyModeless();
dialog->Create(...);
since you want the object to exist beyond the lifetime of a frame-based object.
Of course, this doesn't even come close to covering the fact you'd need to either track the dialog object's lifetime, or make it suicidal.
Steve S
|
|
|
|
|
hello friends!
i am wanted write a program that plays wav's continuously.
i am preparing header for each and playing.due to that
in between the wav files i am getting break.for that is it
possible to prepareheader at first and then passing data
to the buffer(streaming like).If possible pls help me ASAP.
Thanks in advance
|
|
|
|
|
Hi friends,
i have developed a ActiveX Control in VC++ and placed in the browser and i am trying to drag a file into that activex control but Internet explorer opening it........it should not like that...it should display the path of that file....of course i am capturing the file path in actievX control.........
is there any script to disable the opening a file when i dragged into activex control..
please help me its very urgent............client is sit on my head....plz
Thanks
Ramakrishna.J
SoftProSys.ltd.
|
|
|
|
|
Hi all,
I have created a VC++ program in VC++ 6 using "using MFC in
a shared DLL" option. It runs on the Window XP on which it is
being developed, but if I run it on a Window 2000 PC, it prompt out error "cannot find the DLL MFC42D.DLL", what should I do ?
I dont want to link the MFC to the software in a static way.
Thanks
Patrick
|
|
|
|
|
|
Nirav Doshi wrote:
I guess, the MFC DLLs are not present in the target system.
Nor should they be, unless the machine also has Visual Studio installed. The 'debug' libraries are not distributable.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
pyhtang1 wrote:
"cannot find the DLL MFC42D.DLL", what should I do ?
The 'D' at the end of the DLL name signifies that you are trying to run a debug built application on the target machine.
Recompile your program in release mode and it should run OK.
(most machines should have the Microsoft runtime libraries installed)
I Dream of Absolute Zero
|
|
|
|
|
Build your project in Release mode.
It can be done as follows
build/set active configuration.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Hello,
I have an application which hooks up the keyboard of a given process by injecting a DLL into the process.
Now in that DLL, I have a (shared) char buffer which stores each keystroke. I am trying to get the buffer from my application, which is failing! Is there anything I am missing here? :
Here's how my code goes:
<code>
...
#pragma data_seg(".WBA")
char g_chBuffer[0x101];
#pragma data_seg()
#pragma comment(linker, "/section:.WBA,rws")
...
BOOL _declspec(dllexport) __stdcall GetAppBuffer(char *chfBufferOut)
{
if(chfBufferOut == NULL)
{
return FALSE;
}
char *pchBuffer = g_chBuffer;
while((*chfBufferOut++ = *pchBuffer++) != 0);
return TRUE;
}
...
LRESULT _declspec(dllexport) CALLBACK GetKeyboardMsgs(int nCode, WPARAM wParam, LPARAM lParam)
{
...
static char *pchBuffer = g_chBuffer;
...
ToAscii(wParam, nScan, chKeyState, &wTemp, 0);
*pchBuffer++ = char(wTemp);
...
}
</code>
In my application code, where I am calling the function GetAppBuffer() :
...MyFunction()
{
...
static BOOL (__stdcall *fpGetAppBuffer)(char *) = NULL;
if(m_hmodDLL != NULL)
{
memset(chBuffer, STRING_TERMINATOR, 0x101);
fpGetAppBuffer = (BOOL (__stdcall *)(char *)) GetProcAddress(m_hmodDLL, "GetAppBuffer");
}
...
char chBuffer[0x101];
memset(chBuffer, 0, 0x101);
fpGetAppBuffer(chBuffer);
....
}
</code>
Please reply with any of your comments/suggestions. Is there anything wrong, that I am doing here? Please write back even if you feel the question/code is not clear/insufficient.
Thanks!
Rgds,
Nirav
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
Hi!
I wanted a tree control with different back color, line color, and [+/-] icon. To archive the former, I tried CTreeCtrl::SetBkColor and CTreeCtrl::SetLineColor, then it works. But there is trouble with the default [+/-] icon.
I wanted the [+/-] inside a circle. I created 2 icons in resource for that, then tried CWnd::SetIcon big/small for +/-, but the default icon never changes. What should I do?
Thanks,
Sovann.
|
|
|
|