I am new to C# Socket programming. I am trying to build a simplistic application that can detect when a client application connects to the server application.
When connected, I want to send 1 piece of information to the server and receive 1 response back (confirmation).
Afterwards, I just want to know when the connection is broke. Within my application, I do not have to know instantly when the connection is broken, just within the timeout if fine.
Can someone please help me understand what I need to do to accomplish this. Sample source code would be nice, again I am a novice programmer and this topic is way above my head.
I would need help with the client app and server app.
Thanks in advance!
Jorel
I would not begin with sockets if I were a novice programmer. It's not an easy subject to start with, and you need to know more than just how to send a piece of information. You need to know how the protocols work too and how do deal with their way of send/receiving information.
I would recommend you to use wcf instead, since WCF takes care of all lower level details for you. You will just need to know how to send and receive information.
Related
I followed the example on this link.
It worked pretty well - but it worked like a Chat Room.
I dont know how to just send and get message between just 2 clients.
Can someone give me some advices to do that?
Thank you for reading.
As far as I know you cant have only clients. You need to have both, a client and a server.
If you are trying to make a chat program with only 2 users, one of the users needs to act as a server and the other as the client. You only need to put a constraint on the server to allow only one client.
I'm a newbie C# socket programmer and I'm trying to create a C# socket chat application...
here are the requirements of the app..
*it can accept more than one client.
*it should handle those new client on a separate thread.
*the server has a list of active clients and displays them in a list(GUI)
*the server should know when a client is disconnected and will remove it from the list(probably a hashtable or array) of active clients.
honestly, I don't know where to start.
I've been reading through various articles on the net about sockets, multithreading and the likes, but I'm still a bit confused about the whole client/server interaction thing..
Any help/suggestions will be greatly appreciated.. :D
Take a look at ZeroMQ. It was designed for applications like you're describing, works very well, and is free.
I am trying to make an iOS apps which connects to a C# server (using TCP) programmed similarly to that shown here. On the client (iOS) side, I use CFStreams and the CFStreamCreatePairWithSocketToHost method to connect to my cloud server. I have followed the tutorial found here precisely for the iOS side. A copy of the main connection program can be found here.
Unfortunately, when I run the app, I never get a NSStreamEventHasBytesAvailable event from the inputStream, even though the server is programmed to send a message to the client immediately after the connection has been made. Can someone help me fix this?
All help is greatly appreciated, and I always accept at least one answer!
You may want to print out on the server side what was received and what was sent. And you may want to read this, as he does a good job of giving ideas of how to get more info:
bytesWritten, but other device never receives NSStreamEventHasBytesAvailable event
I'm about to start to develop and application in C# but I realized that I haven't the enough knowledge to develop it yet :S.
The thing's that I need to find out a way to let the Web server comunicate with my application, i.e., in short, is there a way to let the web server (not the Client which is the trivial case) send a messege to a Client application?
I know that I way to solve it's to make Client applications periodically send messages to the web server but that's not what I want 'cause polling generates overhead
Sorry about my english! I'm not a native speaker.
Thanks in advance!
Generally this type of interaction is achieved with Comet or WebSockets - I'm not sure how your app will be communicating with the server, but I would bet you can do what you're trying to do using one of those.
You could implement a WCF service in your client that could listen for a connection from the server (or anything else). The server can communicate with the client as easy as calling the API.
Getting started with WCF is really easy using the wizards in VS.
Here is a link that talks about using WCF with ASP, but it can be used outside of asp as well.
It seems like you meant "push" messaging, the challenge around this is for the server to keep track of the lost of clients and manage who should recieve which message.
If you want to get it done with minimal overhead you can check out the Amazon Simple Notification Service.
SNS is a cloud-based messaging and notification service hosted and managed for you, SNS is based on a topic/subscriber model and you set it up via a few simple API calls, it is metered but quite inexpensive for the most part.
edit: For C# Libraries and frameworks to do it yourself, I am not an expert in the C# world so I think other answerers will know it better.
Disclosure: I work at amazon so I am naturally inclined to like their product
I'm tyring to add a feature to my app that sends a nudge to all users of my program (family members inside the house), and when they receive the nudge the window of my app on their computer shakes for a second...
Can somebody please suggest how i'd have to go about this? I've never worked with tcp/ip before.. Is this what I should use, or is there something better?
I have tried to come up with my own solution however none of the samples ever work. So I thought maybe the people on SO might know of other ways?
Thank you :)
If this is just an "in-house" (pardon the pun) application, and you're all on the same network, you might consider sending a UDP broadcast packet. Each instance of your application could listen for a packet on a particular port, and when the correct one is received do the window shake thing.
You might consider UDP for this. Since you can broadcast/multicast via UDP it may be more suitable for this sort of application. There are downsides - UDP transmission is not reliable or guaranteed in the same way as TCP.
I'd go with a good XMPP Library. Maybe Jabber-Net?
You'll also have the added bonus of being able to connect to Google Chat and now Facebook chat later.
You haven't specified if presence in your case requires a server or not. If it is client/server oriented, using XMPP gives you the server side for "free" as a bonus.