Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm sorry if I'm not stating this clearly.** You can ask for any details if required.

**EDITED**

I developed two Windows-Forms-Apps in C# (Visual Studio 2015) using this: NetComm library.

One app starts a server using this code:
C#
Server = new NetComm.Host(2020); //Initialize the Server object, connection will use the 2020 port number
    Server.StartConnection(); //Starts listening for incoming clients


The other one works as a client and connects to the server already started.
Code:

C#
client.Connect("localhost", 2020, "Jack");
    //Connecting to the host (on the same machine) with port 2020 and ID "Jack"


Both apps work fine when I run both on same computer.

1. Run "server" app.
2. Start Server.
3. Run "client" app.
4. Join server.

I just want these to run on two different PC's (These PC's may or may-not share same Wifi-Network).

What I tried is I changed "client's" code like this:

C#
client.Connect(serverIP, 2020, clientID);


Here: serverIP comes from a textBox, IPv4 address of WLAN Adapter of the PC running Server app is put in this textBox.

But it didn't work.

New Edit
The app worked fine when I connected both PC's with a LAN cable completely and then entered Host PC's IP address here.
C#
client.Connect(serverIP, 2020, clientID);

Now the problem is that I don't know how to run this when both PC's are connected to a central Wifi Network.
Posted
Updated 31-May-16 11:40am
v3
Comments
Sergey Alexandrovich Kryukov 29-May-16 17:16pm    
If nothing helped you after 3 days of search, I have a little hope that any answer on this forum can possibly help, no matter how good the answers might be. I'm saying so just because the information on .NET network communication is abundant, detailed and quite clear.

In your search, you missed the most obvious source of information, MSDN, where everything is well explained. Of course, it would take considerable time to read it all, understand, try out, ans so on.

Besides, you did not write anything comprehensible in the "What I have done". To get an idea, please read carefully:
What have you tried so far?

—SA
Member 10283041 31-May-16 17:46pm    
Hey Sergey! Thanks for giving me some spark and Yes, I've tried MSDN as well but things weren't going into my head probably because I was bit (or maybe a lot) tired of doing it for a long time.
I've edited and improve the question. I think it's providing some clear sense now :)
Sergey Alexandrovich Kryukov 31-May-16 21:24pm    
Thank you for your understanding and for the clarifications.
Please see the update to my answer, after [EDIT...].

Also, one way to connect directly via a Wi-Fi network, you may want to create such network, as an "ad-hoc network" on the server-side computer. This is not even a programming topic; just do a Web search for "ad-hoc Wi-Fi network".

—SA

> I think that the problem is related to port-forwarding and ip-addressing,

I doubt it. Run "ipconfig" on the server to find the IP address the client should use to connect to.

You probably have to open the port in Windows Firewall on the server.

Also, how is it you don't know the port on the server? You wrote the server app, right? What port # is it listening on? If you didn't specify a port, it's probably using port 80 as the default.

Marc
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-May-16 17:34pm    
I basically tend to agree; good points; it's just too early to assume anything, when we have no idea what the inquirer really wrote...
—SA
Sorry, from your question, it's not clear how you connected two applications. It can be done on different levels of networking, or even via IPC unrelated to networks.

Please see my past answers:
Communication b/w two Windows applications on LAN.[^],
how i can send byte[] to other pc[^].

You can find all relevant information on MDSN. From my answers, you should see what to look for.

An adequate form of the server-side application would be a Windows Service. Please see:
Services (Windows)[^],
Introduction to Windows Service Applications[^],
Walkthrough: Creating a Windows Service Application in the Component Designer[^].

[EDIT, after the clarifications from the inquirer:]

Thank you for the clarifications. First of all, let's look at this line:
C#
client.Connect("localhost", 2020, "Jack");

Apparently, this line is only good in the server part is on the localhost, that is, it cannot be in a different host (computer). To connect to an application on a different computer, it should be connected to the same network; and you need to pass the IP address instead of "localhost".

You never mentioned that you modified your code to make the IP address you connect to configurable. The IP address should come from configuration data.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900