Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

CSocket receive using pointers

Hello guys,
I have recently been trying to develope a chat application.I want to use dynamic allocation with linked list for my sockets so that the user can modify the max user limit at any time.Now the problem is that the CSocket::Receive dosent seem to work with the pointer.My code is something like this..
CMysocket m_listenSocket;//the listening socket
CMySocket * temp;//the socket pointer

//In the accept or the connect functions
temp = new CMySocket;
temp->Create();

//on accept
m_listenSocket.Accept(*temp);
//or connect
temp->Connect(hostname,port);

Now the program compiles and executes without error.It also connects and accepts connections flawlessly.It also sends data without an error.However whten i call the onreceive the Receive function call fails and the program crashes.I cant understand as to what i might be doing wrong.Please help...

the_void


0
the_void
Asked:
the_void
  • 4
  • 2
1 Solution
 
Leo71Commented:
Try
m_listenSocket.Accept(&temp);
in the meanwhile I look up the two parameters, that you just ignore ;-)
0
 
Leo71Commented:
Strange. I looked it up, the other parameters are really optional and not of interrest if you don't want to know the client that sent the request emidiately.
0
 
Leo71Commented:
Tell me something about "onreceive"
If evereything else works, it's very likely, that something happens before you call temp->Receive.
e.g. how does the temp pointer finds is way into the onreceive function is it a global variable and so on...

Regards
Leo
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
the_voidAuthor Commented:
hello leo,
I need to dereference the socket pointer to get to the memory.It dosent compile otherwise.Anyways, it connects perfectly.I actually tried it with another instance of the program wherein i was using an array of socket pointers.I could send data from this application and receive it without problems at the other end.This program however fails to accept any data.
Temp is global in the main dlg.I do not call temp->receive cause i need to accept data from all the sockets.I just use Receive().This works with an array of sockets.I also tried to specify the socket as in socket->receive() abandoning the whole multiple user idea but even that failed with pointers.
Any help will be greatly appreciated...

also... i do use the sockaddr struct in  my program..i just didnt use it in the example above.

the_void
0
 
the_voidAuthor Commented:
thanks a lot guys, but i figured it out

i needed to use the this pointer with the recieve as in
this->Receive() instead of just Receive() that i used with arrays.

the_void
0
 
Leo71Commented:
I apreciate, that you found it yourself. Other people seems to stop thinking as soon, as they made the post... ;-).
I use the api functions, so I don't have to deal with this and the program get's much smaller ;-).
If I have the joice between class and not I always think if I have benefits of the class. And if not, like in this case where the class just reassambles the api and I don't benefit from the class at all, I choose not to use MFC.

Regards
Leo
0
 
CleanupPingCommented:
the_void:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now