Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CSockets for Client-Server operation

Posted on 2003-11-20
7
Medium Priority
?
360 Views
Last Modified: 2013-11-20
Hi
I am using CSockets for a Client-Server model.( both sides must be able to send and receive )

On the Client side I have a class that extends the CSocket class and overrides the following methods:
       void OnConnect(int nErrorCode);
       void OnSend(int nErrorCode);
       void OnReceive(int nErrorCode);
       void OnClose(int nErrorCode);
       void OnAccept(int nErrorCode);

On the Server side I have a class that extends the CSocket class and overrides the following methods:
       void OnSend(int nErrorCode);
       void OnReceive(int nErrorCode);
       void OnClose(int nErrorCode);
       void OnAccept(int nErrorCode);

I can send data to the Server. But I also wish to receive something at the Client side from the server. Is it necessary for me to do a Listen on the client side ? I tried this but then I can never connect at all to the Server. I dont think I need to even add any code to the OnAccept() function on my client to spawn of another socket. My OnReceive() should be able to handle it in the context of the current socket.  But it doesnt seem to work. What am I doing wrong ?

Note that  sockets on both sides are created as :

BOOL Val = clientSocket.Create(clientPort);
BOOL Val = mySocket.Create(serverPort);

Help !
-P
0
Comment
Question by:prakash_gs
5 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9786483
You need to have listening socket in the server. For each new connection you should create socket which talks with connected client.
Client application should have only one socket which both sends and receives data.

Server:
Listening socket - OnAccept: create client socket which sends and receives data.

Client - socket which sends and receives data.

Check out MFC Sample CHATSRVR.

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9786515
0
 
LVL 1

Expert Comment

by:rami_halim
ID: 9805512
no you don't need a listening socket on the client end, you could but you don't have to.

you should have listen and accepting socket at the server end.
the listen socket waits incoming connections and you accpt it like this

 AcceptSocket.accept ( listenSocket )

on the client end you would only have a clientSocket
and start Connect()
once the connection is established you can send and receive data on both ends..

are you using Async or nonAsync sockets ?..

0
 

Author Comment

by:prakash_gs
ID: 9809086
hi
i figured out my problem.
I wasnt doing a send on the spawned socket that is created on the server on the OnAccept().Instead I was trying to directly send using my parent Server socket. So there ends my travails for now.(I hope...)
Thank you guys.
-P
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 11984794
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

824 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