Sockets: client finding server automatically via name, not IP - c#

I got a client program in Java (Android app), and a server program in C#.
They communicate via Sockets over an internal network.
Problem:
The client needs to have the server's IP address stored, to be able to connect. So, the server needs a static IP.
But now I got to a point I can't have a static IP anymore, so the client has to find the server when it starts up, somehow.
I thought you could use the computer-name to connect via Sockets, but that didn't work for me.
Then I had an idea to just do a broadcast with a basic request, and see who answers (the server from the correct IP), but I have no idea how I can do a broadcast and wait for multiple responses.
And then I also have to find the broadcast address.
Are there any techniques out there that I don't know and haven't come across yet?
Any help is much appreciated! :)

What you are looking is a hostname discovery service. JNDI is an API for discovering hostnames, but it is for java applications.
check this documentation how to use JNDI from .NET framework

Related

PHP server to communicate with WPF application by sockets

I'm trying to create PHP server to communicate with multiple WPF applications (c#), I want it similar to signalR working, where client will subscribe and server broadcast the updates to all clients subscribe with the server.
Please suggest how to start this, I have WPF application running, I need to create the PHP server, i think socket will be used here, as client application will be running all the time and listening to any update from the server.
Any Hint is appreciable.
As you guessed you need to implement sockets to enable communication between your server and the clients. Find a explanation and code example in this youtube video (C#). For the beginning this should help you with your server (php) implementation.
Typically the server is listening for incoming connections and will then deal with them (like it is explained in the video). As I do not know enough of your environment I suggest two options:
One: You make your clients listen for incoming connections. In reference to the video you need to switch the implementations of the server and client socket. For establishing a connection between the server and the client the server needs an address which is normally the ip address.
Two: You can use the typical approach and let the server listen for connections. To imitate the function of the server pushing to the client, you could use a timer at client site and recurringly ask the server for an update. This approch is handy in the case that you can not address your clients from the server as you may not know their ip address for example.
You may want to improve your performance with threading. Find further information here

C# server-client implementation with TCP

I want to create a simple messaging app that uses tcp protocol to communicate, including with multiple people. Messages get sent to the server, which distributes them to all other clients. At the moment, I have it fully functioning and it works perfectly - on a local computer and a local network, using the ipv4 address.
After an extensive Google search, I discovered that to communicate from a different network I need to port-forward my server. However, how do I make my server able to communicate with clients without all the clients port-forwarding? As far as I'm aware, not everybody's device is port-forwarded.
So, how do I implement this? Is it possible with just C#? Or did I misunderstand something, and port-forwarding isn't really required?
Thanks for all the help.
Why don't you use SignalR. I think it will be best for your problem.

Client/Server communication over the internet using ZeroMQ

I am new to zeroMQ. I am trying to develop a simple client server application and I am following the tutorials on zeroMQ’s website:
Server: http://zguide.zeromq.org/cs:wuserver
Client: http://zguide.zeromq.org/cs:wuclient
It’s working fine when I am trying to connect to the server using Local Host Loop Back IP(127.0.0.1) or internal LAN IP but when I attempt to connect over the Internet, i do not receive any messages on the client side.
I have a couple questions:
1- Is this even possible? If not then is there any better way to implement the publisher/subscriber messaging model?
2- Am i doing anything wrong? Do i need to do something differently for communication over the internet?
Hoping to get some positive feedback.
Regards.
You probably have a firewall that has blocked external connections to the port you're using. You might try looking at the admin for your router () and opening a certain port to use for testing.

client server app upnp / port forward question

I am thinking about writing a client server app using sockets in c#. My question is, if the server is behind a router and upnp is enabled, once the server starts listening does upnp automatically forward data incoming to that computer if it is destined for said port? I don't want the user to have to start forwarding ports, I am hoping my server app can be zero configuration.
Thanks in advance.
I worked on a uPNP tool a little while ago for a work application for file sharing across multiple sites.
I can confirm that during the port configuration via uPNP, that you do indeed specify which port and end point you would like to listen.
If uPNP reports back OK. All requests to the port will be forwarded to the passed end point.
I will find the class I made \ modified and give it as an example shortly....

Easiest for two way communication over the internet using C#

What do I use for two way communication over the internet without the necessity to open ports on the client side?
Users won't agree to open ports and do port forwarding on the client side although everything is possible on the server side.
But,I need to accomplish two way communication..
How do I go about achieving this?
It doesn't matter whether its WCF or remoting or webservices...
I just need a quick and fast way to just get the concept to work out and distribute the application.
ofcourse,it's going to be through the internet.
Please help..
Thanks
Edit : Please note that i need to connect multiple clients and maintain a session for each client.
WCF supports duplex HTTP bindings.
As long as the initiating client can access the service, a callback contract can be defined to call the client. It simply keeps the HTTP connection once the client has initiated it.
It depends what you want to do. Duplex WCF can work, but through NAT and Proxies it becomes somewhat "iffy" because it depends on the client opening a WCF endpoint and maintaining the connection.
I wrote a beginners guide to WCF callbacks a while ago - it's simple enough to do, but you'll need to test it a lot, from various client setups.
Connect via TCP (raw sockets, or higher implementation) to a your central server.
Your server should have an application that listens to a specific, well known, TCP port.
Each client connects to your server, using the specific port, and "logs in".
Write an application protocol above the TCP (authentication, session management, etc.), and there you have it, since a TCP connection, once established, works for both directions.

Categories