Socket Programming on a single computer? - c#

I am building a client-server chat application.
It has both a server and a client part.
Is it possible to test the application on the same machine or do i need really need two different computer to run the application.

Yes, it is possible to test your application on same machine.
IP Address of both client and server in this case would be same. Just open different ports for client and server.

Yes, it's possible.
Start your server up and it will listen to a specific port(The server application either has defined one or you have to provide one to it).
Start the client application and make it connect to your machine (127.0.0.1) with the port number your server application listens to.
You may have to modify the application to change the IP address or port number if the program you have does not provide you command line options to specify them.

You can test on the same machine. I am doing this right now as I type this note. :)
Of course normal things you would expect apply...you can't test two listeners on the same port which are on the same interface, for example. But a client connecting to a server on the same box should work no problem.
And of course before you release you should test on different machines as well. This could expose bugs that a single box config does not.

no need, you can bind same IP and different port. they will work.
or you can install a virtual machine.

You can test on the same machine, just make sure the the client and server bind to different ports.

Yes you can test it locally. You can use the loopback address of 127.0.0.1 , your machine name or ip address to connect.
If you are selecting port numbers for your app, please make sure you understand what ports are used and reserved for other programs. For example, if you try and use port 80, you will run into conflicts with people who are running web servers.
Also, while testing locally is great, you need to make sure you understand how your app will need to be configured in different firewall applications and routers.

Related

Cannot connect through tcp remotely

I’m developing an app that connects on port 9050 through the public ip of my server. It works fine on lan but if I’m connected on a different network it fails what can I do to fix this?
first try from Command Prompt this command: telnet ip 9050
if it working means the port 9050 between your pc and the server already opened , otherwise you should check why and where the port is blocked (may be firewall in this case you need to create rule in firewall to pass ).
I don't have any code to go by and I know nothing about your network configuration, but I'll tell you what I generally do when debugging a network-enabled app. First, look at your firewall rules. This will obviously vary depending on what OS you're using but on Windows 10 application-specific permissions are located in Control Panel > System and Security > Windows Defender Firewall > Advanced Settings.
After making sure your app can get through your devices' firewall, check the router settings next. Your packets may not getting by whatever inbuilt security protocols are in place. Since your program works with LAN but not over the Internet, this is a distinct possibility. Also, depending on your network configuration, port forwarding may be necessary; if you're sending data via a public IP address, the router needs some way to know which device on the local network needs to be receiving it. Additionally, if you're trying to connect to your server from the same network you're hosting it on, make sure you use the IP loopback address, which I believe is always 127.0.0.1, or in C# IPAddress.Loopback. Public addresses often won't work when connecting to a local host.
If you're still having problems, I recommend using Wireshark. It's an advanced diagnostics tool that tells you exactly what is being sent and received over your network, and can help pinpoint otherwise hard to spot issues.

How to communicate with a computer in a different Network

So I have already made the GUI and the program and all, and I want the option to enter an ip address on 2 computers in different networks (i enter his and he mine) and that we they communicate logs.
Both computers compute something and need to compare the values they compute, so i want to send arrays back and forth.
All that works already without the actual communication. I do not have a server I could use.
It doesn't matter in which network the PCs are for your program.
You just need to make sure the packages are routed correctly, so that it is physically possible to access one pc from the other (via its ip address).
In your program you can just use a TCP connection with the TcpClient and TcpListener class to send your data back and forth. All information you need is the IP and Port of the PC to connect to.
A third-party server you mentioned is not necessarily needed if you have just two computers communicating in the same way all the time

How to run TCP Sockets application from different computers

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
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.

How can make my c# messenger works on the internet not only on the local networks?

I'm working on a simple c# messenger and its works on the local network only. Does somebody know what should i do to make it works on the internet?
The solution contains the server project that listening on a certain port, and a client project connect to the server with that port.
Your clients need to be able to communicate with the server, which means that either:
You need to host the server application on a computer that is directly connected to the internet.
You need to setup port forwarding on the router that controls internet access for your network.
In either case the clients will need to know the IP address to connect to, and any firewall interactions need to be considered. This may also include ISP firewalls, as some ISPs limit inbound connections to subscriber connections.
I won't go into the specifics of setting up port forwarding on a router... there are plenty of examples, and every router is different. Google will help you with this if necessary.
Ideally you should have a static IP address for this, or some method for the clients to locate the IP address that your server is hosted on. If you must run from a dynamic IP address (such as some ISPs still use for subscribers) then one of the Dynamic DNS options might work for you.
In-order to make it work on Internet a simple answer is you need to enable ports which is used for communication.Generally the ports will be blocked by the Companies firewall for security reasons.So contact your IT dept to enable the port.
Or Use common port like 80.

Can localhost be both client and server for development?

Referring to a question I asked on SuperUser, which is recommended to be ask on SO.
I am developing a console application that sends packet to a remote server on a specific TCP Port (55000). I only have one computer to develop and test on. Is it still possible to debug my program; i.e. when I F5 debug, I send a test packet (from localhost) to localhost which is listening.
Also, I need to open up a port for development. I follow the this instruction to open a port (55000) in Window 7.
But when I netstat, the port 55000 is not even listed (i.e. the Local Address of 0.0.0.0:55000 is not there...). I also tried restarting the computer, but persist the problem.
Yes, of course you can. Just run the server to listen on port 55000, and then connect to localhost on port 55000.
You can use 2 different sites in the IIS with different ports or you can take advanatege of 'hosts' file to assign some naming for those 2 sites
Yes, it is possible. Although keep in mind that TCP ports for request and response must be different. So, if you bind your server to some port (say 2000), then your client must send requests from different port (80 usually).

Categories

Resources