Solved

CSockets for Client-Server operation

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

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!

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses

623 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