473,666 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Communications Breakdown with CSocket

The following describes a problem I have been having for the better
part of 3 months, for approximately the last month however I have been
focused solely on solving it and seem to be no nearer now than a month
ago. Any thoughts or suggestions that might lead to a fix would be
greatly appreciated.

I have to VB based applications on two different PC's, a client and a
server which use a pair of OCX's to provide a communication method
between the two and which use an overloaded version of the CSocket
class.

A problem has arisen where communication between the two OCX's will be
interrupted. The socket will appear to remain open as the
Disconnection event on either side has not been fired, however neither
side is able to hear the other (even when sending on the other side is
occurring).

While not 100% predictable, the only times the communication breaks
down is when the method SendPlayList or one of a couple other Server
side OCX methods fire which send a string. Note: These functions to
not cause a break down each time they are called, but seem to
ultimately be responsible for the break down.

In trying to track down this issue, I have implemented critical
sections on both the client and server side (sending and receiving
both) to help to ensure that multiple sends or processing of received
data does not occur. I have also implemented basic checking (to be
removed later) to ensure that that the correct amount of data is being
sent and received each time.

Below is some of the code being worked with:

On the VB server side, we have the server OCX instantiated and named
Remote, we call the SendPlayList method of it, passing the string
sPlayList as such:
Remote.SendPlay List sPlayList
Within the server side OCX, the above line calls the following
function:

void CSRemoteCtrl::S endPlayList(LPC TSTR PlayList)
{
PACKET_HEADER hdr;
BYTE* pData;
int iBufSize;
SendCriticalSec tion.Lock();
if (lstrlen(PlayLi st) > 0)
{
if (m_pClientSocke t != NULL)
{
hdr.cmd = SERVER_PLAY_LIS T;
hdr.size = lstrlen(PlayLis t)+1; // +1 for NULL terminator

iBufSize = sizeof(PACKET_H EADER) + hdr.size;

pData = new BYTE[iBufSize];
memcpy( &pData[0], &hdr, sizeof( PACKET_HEADER ));
memcpy( &pData[sizeof(PACKET_H EADER)], PlayList, hdr.size);

int iRet = m_pClientSocket->Send(pData, iBufSize);
if(iRet != iBufSize)
AfxMessageBox(" Disconnected due to wrong count of bytes sent");

delete [] pData;
}
}
else
{
hdr.cmd = SERVER_PLAY_LIS T;
hdr.size = 0;

int iRet = m_pClientSocket->Send(&hdr, sizeof(PACKET_H EADER));
if(iRet != sizeof(PACKET_H EADER))
AfxMessageBox(" Disconnected due to wrong count of bytes sent");
}
}
On the receiving side within the client OCX, the OnReceive function
fires when new data arrives, inside of it there is a switch statement
which contains the following:

Receive( &packetComma nd, sizeof( packetCommand ), MSG_PEEK );

switch( packetCommand )
{

//... Other Case Statements

case SERVER_PLAY_LIS T:
{
PACKET_HEADER packet;

// Receive the packet structure
iRet = Receive( &packet, sizeof( packet ));
if(iRet != sizeof(packet))
AfxMessageBox(" Size Error 1 in: SERVER_PLAY_LIS T");
// Catch the file if it is attached
if( packet.size > 0)
{
char *filenames = new char[ packet.size ];
iRet = Receive( filenames, packet.size );
if((UINT32)iRet != packet.size)
AfxMessageBox(" Size Error 2 in: SERVER_PLAY_LIS T");
// Activate the event
pCRemoteCtrl->FirePLAYLIST ( handle, filenames );

delete filenames;
}
else
{
// Activate the event
pCRemoteCtrl->FirePLAYLIST ( handle, "" );
}
}
break;
//... Other Case Statements

}
A couple of conventions being used here is that the packets I am using
have a header sections which contain an enumerated value which
describes the kind of packet it is, based on that, a different type of
payload packet will be used to read the data and process it, similar
to how the sending side works.

Most of the time, the above code, along with similar blocks functions
flawlessly, but now and then, this or several others can and does
bring down the communication.

Also, this code is the 3rd version of code which has been used in the
same way (providing TCP/IP connectivity between VB apps) and is the
first to exhibit these problems, thus I require an easy to implement
solution which does not require rewriting or modifying large sections
of it.
Jul 22 '05 #1
5 1803
Brendan Grant wrote:
The following describes a problem I have been having for the better
part of 3 months, for approximately the last month however I have been
focused solely on solving it and seem to be no nearer now than a month
ago. Any thoughts or suggestions that might lead to a fix would be
greatly appreciated.

I have to VB based applications on two different PC's, a client and a
server which use a pair of OCX's to provide a communication method
between the two and which use an overloaded version of the CSocket
class.

<snip MFC code>

Only the standard C++ language and its library are topical here. MFC
questions should be asked on microsoft.publi c.vc.mfc.

- Pete

Jul 22 '05 #2
> Only the standard C++ language and its library are topical here. MFC
questions should be asked on microsoft.publi c.vc.mfc.


I know, and have done so. Unfortunately being unable to find an answer
most anywhere I have looked, I have been forced to expand my search
for a solution to just outside of the normal area.
Jul 22 '05 #3
Brendan Grant wrote:
Only the standard C++ language and its library are topical here. MFC
questions should be asked on microsoft.publi c.vc.mfc.


I know, and have done so. Unfortunately being unable to find an answer
most anywhere I have looked, I have been forced to expand my search
for a solution to just outside of the normal area.


Well, that still does not make it topical here. :)
Would you ask your question, say, rec.gardens.cac ti? Your question has
nothing to do with the topic of that group, and not this one either.

- Pete
Jul 22 '05 #4
"Pete C." <x@x.x> wrote in message news:<fPkyc.181 5>
Well, that still does not make it topical here. :)
Would you ask your question, say, rec.gardens.cac ti? Your question has
nothing to do with the topic of that group, and not this one either.

- Pete


Your comparison is completely without merit.

Most MFC programming is done in and with C++, so it is not too long of
a shot to think that someone on a C++ group might have encountered
this problem in their time who does not read an MFC group.

It is far less likely that such a person would read rec.gardens.cac ti
and be a MFC or C++ programmer.

My question, being based in C++ does thus still have a place in a
group such as this.
Jul 22 '05 #5
gr****@dahat.co m (Brendan Grant) wrote in message news:<d5******* *************** ****@posting.go ogle.com>...
"Pete C." <x@x.x> wrote in message news:<fPkyc.181 5>
Well, that still does not make it topical here. :)
Would you ask your question, say, rec.gardens.cac ti? Your question has
nothing to do with the topic of that group, and not this one either.

- Pete


Your comparison is completely without merit.

Most MFC programming is done in and with C++, so it is not too long of
a shot to think that someone on a C++ group might have encountered
this problem in their time who does not read an MFC group.

It is far less likely that such a person would read rec.gardens.cac ti
and be a MFC or C++ programmer.

My question, being based in C++ does thus still have a place in a
group such as this.


The topic of the group is *Standard* C++, and not MFC. In your code,
there are lots of identifiers which are neither part of the Standard
Library, nor have you declared them yourself.

!!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2062
by: kids | last post by:
Can i post question related to CSocket here? Thanks
0
2493
by: Dana Morris | last post by:
Call for Participation OMG's First Annual Software-Based Communications (SBC) Workshop: From Mobile to Agile Communications http://www.omg.org/news/meetings/SBC2004/call.htm September 13-16, 2004 Washington, DC USA Introduction
1
1491
by: Catherine Jo Morgan | last post by:
This is for a recreational tree climbing database. When a climb is arranged, it often begins with one or more inquiries by phone or email. Sometimes it takes several communications to answer questions, set dates, etc. At some point an inquiry gets definite enough to become a JobProposal, with a specific type of climb, dates and fee set, etc. Usually JobProposals become Climbs when the inquirer signs a contract, pays the deposit or fee,...
6
6974
by: Peter Krikelis | last post by:
Hi All, I am having a problem setting up input mode for serial communications. (Sorry about the long code post). The following code is what I use to set up my comm port.
1
2291
by: Bryan | last post by:
I have created an MFC ActiveX control. If I connect to my local machine on some port, everything works fine. If I try to connect to a different computer, I get an error (from CSocket.Create) that says "The requested address is not valid in its context." I know for a fact that the address is valid because I can have one of my Java Programs connect just fine... Is there just something about using an ActiveX control to create a socket...
0
2140
by: BuddyWork | last post by:
Hello, I want to know if there any good tools out there which will show me a breakdown of the memory allocation in Gen 2 heap, basically a breakdown by object is what I'm looking for. The reason for this is that I eventually get the OutOfMemory exception. I can see the GEN2, GEN1, GEN0 GC kicking in but when run a pariticular code approx 2333
4
2987
by: Gary Frank | last post by:
I'd like to write a program in VB.Net that handles serial communications to several devices. VB.Net 2003 does not have adequate built-in serial communications. I heard that 2005 will have that. Has this serial communications functionality been built into 2005 Beta yet? If so, is there any reason I can't get the Beta and create the program with serial communications now?
0
1120
by: hsdas | last post by:
Hi, I started using CSocket as Winsock Control in VB6 do not allow to transfer UDTs. Can anybody who have used CSocket show me some light on how to use CSocket to Send and Receive UDTs....Quick help is appreciated. Thanks in advance.
3
4598
by: Daron | last post by:
Is it possible to use SQL to take a field, and break it down by denominations? I would like to take a field, and then break this out into the number of bills($100's, $50's, etc) I would need: $469.32 = 4x$100 1x$50 1x$10 1x$5
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.