?
Solved

CSocket receive using pointers

Posted on 2003-03-17
8
Medium Priority
?
212 Views
Last Modified: 2010-04-17
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
Comment
Question by:the_void
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
8 Comments
 

Expert Comment

by:Leo71
ID: 8154074
Try
m_listenSocket.Accept(&temp);
in the meanwhile I look up the two parameters, that you just ignore ;-)
0
 

Expert Comment

by:Leo71
ID: 8154167
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
 

Expert Comment

by:Leo71
ID: 8154205
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:the_void
ID: 8156538
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
 

Accepted Solution

by:
the_void earned 0 total points
ID: 8158312
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
 

Expert Comment

by:Leo71
ID: 8161675
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
 

Expert Comment

by:CleanupPing
ID: 9447068
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Starting up a Project
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question