0

I would appreciate if someone could help.

I have written a Client/Server Sockets application. The client is Windows Forms C# app and the server is a C# console app which runs locally. The client application has a login form containing the field with generated port.

When user logins he is connecting to the server using that port and the server continues listening incoming connections.

Everything works fine when I test my application simply running several instances of Visual Studio project on one PC. Now, I would like to test it on several PCs and I am very confused here. I would be grateful if someone could explain in simle words how to run my app on two machines.

How do both users connect to the same server? Where should it be located? Should the server have one IP and different ports per one users group?

Also, my application uses SQL Server Database which is installed locally on one PC. So the application uses connection string with that PC Name. In case of two PCs is it possible to connect the second computer to DB on first PC?

I am sorry if this sounds silly :)

Thanks a lot

Gyuzal
  • 1,581
  • 10
  • 52
  • 99
  • 1
    You could let it listen on port X, tell the client to call back on port y thereafter. Sort of how IIS works (or passive FTP) – Anthony Horne May 06 '14 at 08:23

1 Answers1

1

So if I am correct you are wondering the following three things?

Q1. How do I test my software in a multiple machine environment.

A: This is perhaps not really a Stackoverflow question but what I would do in this case is to have a small setup in Hyper-V with several machines with different operating systems that all have a shared folder that I can deploy my code to. Of course for more extended testing you would need to get more machines and copy the executables to that machine for testing for the first stage and perhaps write a setup software for the second stage of testing, but that depends on the how much testing you actually do.

Q2. How to I allow several users to connect to my service?

A: I think that Anthony Horne has a great answer to this in the comments - Tell your service to listen on port X and when a client tries to connect open a new communication instance on port Y and ask the client to call back to that port. This is as far as I know industry standard for solving this type of problem.

Q3. My application uses a SQL Server Database can I allow clients to connect to it remotely.

A: Yes you can. Please see this Stackoverflow question.

Community
  • 1
  • 1
Karl-Henrik
  • 1,113
  • 1
  • 11
  • 17
  • Thanks for your reply. So the server should be running on one PC? How can I switch ports if the port is defined then server starts, or should I restart it? – Gyuzal May 06 '14 at 08:56
  • Define a listener port at the start that does nothing but receive incoming requests for connections, the listener never changes the port but rather starts a NEW service on a different port, tells the client what the port of the new service is and then hangs up. The client can then use the information an call back to the new service. More clients can then call the listener and each one get their "own service" for the duration of the session. – Karl-Henrik May 06 '14 at 08:57
  • Can I get the port from localEndPoint of the client Socket and then rebind it to the listener socket? – Gyuzal May 06 '14 at 09:37
  • No you should #1. Create a new instance of a communication service in your code. #2. Send the port for the new instance as a message to the client so that the client can create a new connection to the service on the new port #3. Disconnect the client from listener so the listener can be free to listen to incoming connection requests. #4. Connect to the new instance of the communication service from the client over the new port that the client received from the listener. Experiment some and the come back and show us some code if you get stuck – Karl-Henrik May 06 '14 at 09:43