Web application client server - c#

I want to create a client/server web application. The client and server can exchange data back and forth. When i say data i mean like a number, for example (0,8,7...), so everytime a client presses a button it sends a number to the server and the server send an acknowledgement back to client. The cleint side i want to put it on the internet so you can access the server from a browser.
Is silverlight socket the way to go? I know theres port restrictions but im planning on using my personal router to open up the ports. Or is socket only for local connections???

Assuming you just have no idea where to start, I'd say you should start by learning about WCF (Windows Communication Foundation). Obviously, start with the beginner's guide. There are some nice introductory videos there that should get you going.

If there is such a thing as Silverlight sockets, you can use them. I'd rather use WCF. Sockets aren't restricted to local connections, but you should be aware that using ports different from 80 in Web applications can restrict some user from accessing your them.
I would like to add that sockets aren't the fastest local connections, but are the base of almost all inter-machine communication.

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

Two-way Communication between Server and Clients

Situation: We have a web application running on a server. This application needs to fetch data from some other PC(Clients), which are on a different network.
On the clients' pc there are WCF hosted in Windows Services using its their local Sql db. i want to make duplex communication between server and clients for share data with each other.
data share mean share data-table,data-set,string etc between clients and server .
Problem :
1) I have no control over the firewall, proxy, NAT on the client side PC. Mostly company Employee PCs have lots of network security e.g firewall block ICMP traffic and some port too, some Router might be Disabled port-forwarding etc etc , client can change network place.
I don't want to make any setting on client side Router,proxy,firewall though .
during communication how can i handle that's kind of issue of client side?
as you know skype is working perfect in that situation.
firewalls very often block inbound connections to clients; the client may not be reachable from the server, it may be using NAT translation behind a router and so cannot be contacted without port forwarding being set up on the router and some new router disabled port forwarding .
2) On clients side there is no IIS .
I don't want to allow remote access on clients PC.
There are more than 100 Clients and only one Server. one server need communicate with many clients on different network .
3) One side my client application is using window application and wcf hosted in window service ,Other side on my server i'm using Web application . so its mean communication is between desktop pc and web pc , that's issue .
If both using a web application then it was not issue to make duplex communication.because i know WEBRTC is fit there lol.
Technology which i had already test and find issue
WSDualHttpBinding: Not work if client behind NAT. check this for detail click here
MSMQ : its bad technique if clients more than 1 and performance issue also because its use RAM memory . check here click here
Xsocket: Its also not work if ICMP traffic block by firewall on client. check here click
WebRTC: Its work fine but its support web to web communication .as my client side i have win app.
Socket.io: Its need to set up node.js and many other thing , hard to implement because i need implement on existence application , i am not making new application.
C# Socket Program: Its wouldn't work if client behind NAT.check here click for detail
Service Bus relay: Its not free even for testing .
socketPro: I studied i find its good but i can't find any right sample on google .so that i could test that.
Genuine Channels: I can't find any sample on google .
Lets see SignalR issue .: Server side i run a console application and Client side i run two application ,one is console and other web. when i was running console client application than it was not initiating connection with Server but when i was using web client application then it was working fine.
sample link is here SignalR two way communication
I can't understand why thas??
Please tell me What is best most secure and fast way to handle this situation? what approach should i use ?
SignalR seems to fit for this solution, because it's flexible.
It negotiates the fastest available channel of communication and that is what you are looking for.
You should investigate the problem with it and signalR will eventually work.
I'm using SignalR extensively to communicate between the servers (C#), between server and mobile apps (C#, Xamarin, iOS, Android). The servers are at different locations and the mobile apps can be anywhere. It all works very reliable.
Take a look at: http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host and here http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-net-client
I've been working in my spare time with sockets (admittedly in c++, not c# but there shouldn't be a difference), and I've never had an issue connecting to clients behind a firewall/router, even without port forwarding.
Routers and firewalls generally don't like server-like programs, eg. programs that bind the socket to a port number. Does your client do anything related to binding? Because it shouldn't.
Needless to say, I would suggest a socket program. The way I see it, it's the most flexible way.

Server communicate back to multiple different clients

So I got as an assignment to make a small chat function where multiple clients should be able to connect to a server and communicate with it, the server should then be able to choose whom it wants to communicate back with. (From a dropdown list or something).
What I've been able to do so far, with help from some tutorials, is that clients can connect to the server and communicate with it but nothing more. The server can't communicate back.
I'm very new to this and have limited knowledge in both C# and TCP/IP.
https://gist.github.com/4565988 <-Contains both code for client and server.
So I what I need help with is a way for the server to reply to different clients and for the client to recieve a message from the server.
Any help is appreciated!
Best Regards, Fredrik
With regards to a starting point, I would have a look at WCF Duplex Services. Duplex allow you to subscribe to the service and send updates out using two-way communication.
Essentially you can create the server as a WCF service with a couple of methods: getclients and sendMessage. From there, a client can then subscribe to the service and (while connected) get a list of other subscribers (which you provide to the UI) and then send a message back to the service (which will then use duplexing to send it to whomever it needs to).
As long as you're not married to using sockets, this would be a lot easier than creating a protocol and managing a list of connections. There are also examples of using WCF as a chat medium available on code project.
For TCP knowledge I reconn Barbara Heckler's vid where she shows a brief implementation of such kind of server. Unfortunately in Java, but nevertheless very useful.
I reconn minute 0 - 15 for the basics (UDP) and 15 - 40 for the TCP connection and why mutlithreading is need for TCP but not for UDP.
http://www.youtube.com/watch?v=5QzNHEcLp10
It's pretty simple, really. That TCP stream you successfully extract and use to read what the client(s) sent can also be written to in order to send back something, so all you have to do is move the connection and stream objects out to shared collections of some sort so that your server-side sending logic can get at it when it wants to send something. Similarly, in the client you would issue a read on the TCP stream to read what the server sent.

sending data to the server via port 5555 C#

I am wanting to send some data to a server from a client application to the server via port 5555. I don't have a window's server. My question is if I purchase a .Net Framework hosting service. Would I be able to connect the client application to this server. and could I do it by sending a Post. I am new to this, so excuse me if it doesn't entire make sense. but I am looking for just some little direction. If someone could explain what port 5555 is used for that would be great.
Most hosting provides will only allow incoming connections on the standard web ports (80 for unencrypted traffic/http and 443 for encrypted/https). Outgoing connections are less likely to be restricted, but it is not uncommon that only a few specific ports are open.
If you're developing a custom solution and you do not need a connection that allows you to continually send data back and forth, then a hosted solution will do fine. If you do need the live link or custom port numbers then you'll need to upgrade to a virtual managed server, which is essentially your own virtual copy of a Windows server. This costs more but allows you to listen on custom ports - essentially do as you please.
As for determining the specific use of a port, most networked applications have simply picked one or more numbers without much research. IANA maintains a list of protocols/applications/services and their associated port numbers, but being listed requires that an application is sent and approved.
Custom port for data exchange + tcp/ip has been identified to be very difficult across the Internet, due to firewalls/gateways everywhere.
Why not use REST web service or SOAP web service for data exchange? That has been proved to be a firewall friendly approach as it uses port 80 or 443.

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