Solved

CSockets for Client-Server operation

Posted on 2003-11-20
7
337 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
7 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

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 110
maxBlock challenge 30 145
if loop in java 3 160
Problem to event 3 112
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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