C# server-client implementation with TCP - c#

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.

Related

use socket to send data on internet

When I send data using socket in C# on LAN, everything works fine, but how do I send my data over the internet. How to send while the sever I create uses the ip from my compute (private ip)
Can someone suggest on how can I achieve this, basically I should be able to send data anywhere over the internet, not just on LAN.
These days most computers have a router with a firewall between them. Routers, via secreuity design, stop direct access to the computers behind them and their local network.
Yes you will either have to
configure the router to map through a specific port to one of your computers.
Or, the more common way to do this is using a central hub, ie a Web service as an intermediary. This way no firewall are needed as both computers are only connecting one way (out). You could use a wcf service or Web api or many technologies to achieve this and usually you'd use a database to store you game state which makes it persistent

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.

Instant Server-Client Communication, C#?

I have been doing research for a few months now on the possibility of client-server communication. I have experimented with many methods such as WebORB and FluorineFX, which are both servers designed to deal with client/server authentication.
WebORB only runs on Windows for their .NET version as far as I can tell, and I would much rather use an open source system. I have tried using FluorineFX, but I think their must be a simpler way for me to build my own simple system from the ground up.
I have been using Dropbox for a while now, and I like the way that the client-server communication is instant. As far as I can tell (from some Google searches) the client doesn't open a port of its own, and just communicates with the Dropbox server through port 80. An example of its instant communication is where you may delete a file on Dropbox on their website, and instantly the server communicates with the client telling it what has happened. I don't know how this instant communication is possible without opening a port.
I can create a system that uses fetching from the client, asking the server every 10 seconds or so to see if there are any updates, but I would like a method to be able to push the information from the server to the client.
My server runs Linux so I don't think I can use WCF, and ideally I am looking for a way to make PHP and C# communicate with each other.
I would love to hear any advice that anyone has and how they deal with the problem.
Cheers.
You CAN use WCF to communicate with any platform. Just make sure you're using an endpoint which your target machine support: http://msdn.microsoft.com/en-us/library/ms733107.aspx
Have you tried the good old .NET Remoting which runs perfectly with Mono?
You can choose between a TcpChannel (for performance) and a HttpChannel (to pass proxy/firewall easily).
For push notifications, you can open a connection to your server and wait for an answer indefinitely.

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.

Share data in LAN

I'm building a music library program, and I want to have the ability to share the library in the LAN. How can I discover others who share their library? I'd like to find others' libraries without typing in IPs and stuff.
Apple uses mdns (they call it Bonjour) to broadcast and discover music shares on the local network without any user configuration.
Many other manufacturers implement UPnP/AV for the same.
Probably the easiest way is to use UDP to periodically send a message (containing some info advertising your library's presence) to the broadcast address. This will be received by all the hosts on your subnet (and perhaps further, depending on your router configuration). If your app listens for these messages from other hosts, it will over time be able to find all the other instances of your app on the subnet.
Edit: found this question which has answers that go into more specifics of what I'm talking about.
SNMP
This protocol was designed for what you are looking to do.
There are several libraries that you could use that implement SNMP which would make it easy to send and receive.
You could get your application to send the fact that the library is shared to a central server - in fact just send the location.
Other instances of your application could then just ask the server for the list of shared libraries.
The advantage of this is that your application isn't constantly broadcasting.
The disadvantage is that you need a central server.

Categories