Link to home
Start Free TrialLog in
Avatar of the_void
the_void

asked on

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


Avatar of Leo71
Leo71

Try
m_listenSocket.Accept(&temp);
in the meanwhile I look up the two parameters, that you just ignore ;-)
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.
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
Avatar of the_void

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of the_void
the_void

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.