Using Sockets in C#

A

ahmed.maryam

Hi all,

I have a weird situation here in that I've designed two C#
applications that need to communicate with each other using sockets.
So I am trying to set the applications up in a way that one acts like
the 'server' and the other a 'client'. However, the 'server' is an
application that does some work, and one if its jobs is to launch the
other application and start communicating with it when a user clicks a
certain button. The other application will then open up and begin
passing data back and forth with the 'server'. The problem is, how do
I get the SERVER to INITIATE communication with a CLIENT instead of
waiting for a connection the way servers traditionally do?

Any ideas how I could approach this problem? Thanks!

~ M
 
A

ahmed.maryam

I just want to add that maybe the client/server architecture isn't
best for this scenario. I don't know if there's a way for me to have
the 'server' application spawn a new process that initiates
communication between the two apps? No idea how to get started!

~ M
 
G

gshzheng

You may encapsulate all the socket function into a dll-project. In this
project, you start tcp-listenning ,waitint for
client connetion. Then publishing a event when receive something form
client.

Your main project do not care any socket business,just refrence the
dll-project and subscribe the event.So the main
project can do what it want .

Surely, a lot of thread will be created in your project.
 
A

ahmed.maryam

Nevermind I figured out a solution to the problem. If anybody's
interested, the way I solved the problem was allowing my server to
call "sock.Listen", and then when the other application was launched,
I called "socket.Connect" in the client, passing it the IP address and
Port of the server. This way I can develop communication between two
C# applications where the server launches the client.

Thanks for reading!

~ Maryam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top