Need help with C# Server/Client style program - c#

I've always wanted to learn TCP or UDP(I hear UDP sucks though) in C# but I can never find ANY tutorial that can teach it. I mean, I've googled tutorials to the point where the results aren't even relevant anymore. Almost every tutorial I've come across explains TCP as if I already knew it, or they introduce terms but never explain them. After a few months, I have made absolutely NO progress. Any help here?
Note: I am not a beginner programmer, I have experience making programs. It's just the TCP tutorials out there suck.

You're possibly searching with the wrong keywords. The keyword is sockets. The TCP/IP programming API is called sockets, on pretty much all platforms including .NET.

try codeproject.com
They have a lot of tutorials with pretty good code samples about TCP/UDP communication (among other things).
One of the many

I think it's difficult to find tutorials for TCP and UDP specifically because they are specific protocols (although very frequently used) and Microsoft are trying to abstract all these concepts so that your application is not dependent of the underlying technology.
Nowadays, you'll be advised to use Windows Communication Foundation (WCF); and you have a lot of resources from MSDN or the beginner's guide.
By the way, learning TCP cannot be done with a tutorial, but with a book focused on networking such as this one. If you do so, you'll also learn why UDP doesn't "suck"...

The reason there is no Cä# toutorial is because it is not needed. You basically ask "is there a course telling me how the rules are on streets when I drive a mercedes". Hint: there are the rules how to drive n streets, and theree is a manual for a mercedes car.
Or: There are books about the IP protocol, and then there is the .NET documentation how .NET implements this. If you ever want to be more than a junior in the field of programming then better get used to learn abstract concepts separate and do not expect a full "howto" for every simple step.
Now, TCP / UDP are fully separate items. They both extend TCP and they have very different uses. Saying "udp sucks" would be quite ignorant towards a lot of programs I know that would never work with TCP and require the fast and easy data distribution of UDP (which, cont´rary to TCP, also supports multicast). Most of my traffic counting in gb) external these days is UDP based because udp does not get stuck on a lost packet, and list packets can be easily requieried with a specialized higher level (application level) protocol. TCP has the really nasty habit of getting stuck up to 3 minutes when a packet is lost. Sometimes (like: financial data, voip) this is not really acceptable. Most programs love the easy handling of TCP, but it comes with a significant price.

UDP is a different beast.
however, I found this very useful as a starting point: TCP/IP tutorial

I've written some .NET-based TCP/IP posts on my blog.
They're not a tutorial; rather, they are a few articles on common mistakes. I'd recommend reading them after you understand the tutorials. I also list a couple of good TCP/IP books under the resources section.

Related

C# socket client-server libraries (Nuget/other?)

I want to start writing games/applications with client-server architecture. I explored the internet and everyone tells that the best way is to use c# built-in socket libs. But If I am forced to write everything on my own (singletons, threads, keeping connection alive, parsing in-out messages etc.) I bet I will do it for months. Do you know any library supporting client-server based connections for C# (Forms/WPF/maybe Mono)? I can not find any "quite new" threads/information about this.
i think your problem will be, that you will not find an predefined lib which fits your requirements.
But if you write it with Visual Studio autocomplete will help you a lot.
However there are lots of question for me. What exactly is your target? What kind of game do you thinking of?
These factors affect your complexity of your "socket" enormous.
I think for a small "Ping Pong"-Multiplayer-Game your Socket is quite easy to do.

wcf vs c# network programming

I want to study network programming, there’s a chapter named “networking” in “C# in a nutshell”, this chapter contains ‘WebClient’, ‘HttpClient’, ‘FTP’, ‘TCP’ and so on. But some body tell me to study WCF, I want to know what’s the relationship between WCF and c# networking programming, I remembered I have seen somewhere that WCF encapsulates network programming, it’s more flexible and convenient, but not efficiency. Does this mean the relationship between them like ado.net technology with orm? Which I should to study, network programming or WCF? Does c# network programming an obsolete technology?
Thanks
"network programming" usually refers to sockets, this is the lowest level of network communication and deals with pushing bytes on the network - all the other communication systems are built on top of sockets.
Most projects don't use sockets directly because there are simple higher level systems you can use but I think it's still worthwhile to learn the basics because it's not so complicated and it will help you deal with problems in those higher level systems.
The next level is WebClient and friends, those are relatively straightforward classes that implement a communication protocol on top of sockets (for example HTTP).
It's definitely worth your time to learn how to use those because they are simple and extremely useful (for example if you want to pull a file from the internet or communicate with a 3rd party service).
At the highest level you have WCF, this is an extensive (and in my personal opinion over-complicated and over-engineered) framework that gives you a class interface for an external network based service while trying (unsuccessfully) to hide all the communication details.
WCF is very popular in big organizations and "enterprise systems", so, if you want to get a job developing enterprise systems for big organizations learning WCF is a very smart career move.
So, my advice, start with sockets, learn just the basics - this will help you understand how things work under the covers (this will become very useful when you have to debug network problems).
Than move on to the higher level classes, write a simple program that uses WebClient to read a page from the internet so you are comfortable with the concept, don't bother
with all the advanced options, they are there and you can look them up later when you need them.
Learning just the basics of sockets and WebClient should take just a few hours, after that (if you want to work on big systems) learn how to use WCF.
Then you will have the WCF knowledge for your resume and you will know how to just get something over the internet with a few lines of code without using a gigantic framework when you don't need it.
If you want to study network programming you'll want to read about sockets and TCP/IP (and later on UDP if you want to stream or smaller packets). Sockets are the API that most OS:es uses to handle protocols like TCP/IP.
Your comparison is correct. WCF is a framework on top of the networking layer in .NET. Just as ORMs are frameworks on top of ADO.NET.
WCF is not the so called network programming. They are two concepts with some relationship.
Usually network programming means socket programming and TCP/IP. You are supposed to be familiar with protocols, such as HTTP, FTP, SNMP and so on. Then you can write programs that serve as protocol servers and clients. Network programming is still hot, though it is no longer that popular.
WCF is a framework for web services, which is HTTP only (mainly SOAP).
If possible, you should learn both or at least know of both.

Looking for descriptions and guidance on the use of advanced Socket Options

I'm refactoring some old Socket routines and I'm struggling to make sense of some more advanced Socket Options (specifically System.Net.Sockets.SocketOptionName) and the implications of removing/adding them.
For Example... DontRoute, OutOfBandInline, SendLowWater/ReceiveLowWater, DontFragment, BlockSource, NoDelay, NoChecksum, etc...
A full list can be found at http://msdn.microsoft.com/en-us/library/system.net.sockets.socketoptionname.aspx
Can anyone recommend a source where I can get more detailed guidance/descriptions on socket options? Although my focus relates to the overall performance of the sockets, I'm also interested in gaining some context with regard to the appropriateness of various options under different circumstances.
I implemented sockets between Windows system and VxWorks. I believe I used this as a start # Code at CodeProject.
CodeProject site has a history of legacy codes.
I just found out Wikipedia has full sample code on TCP/IP sockets with explanations! It's at BSD Sockets
The advanced socket APIs are not well documented on the .NET side of MSDN. You have to look in the unmanaged side.
Fortunately, the low-level Socket class and its associated enums are almost a 1:1 mapping to the unmanaged functions/values. e.g., here's the listing of meanings for the setsockopt values.

OSI Layer 2 Network Programming

I've recently taken some classes in networking (CCNA 1 through 4), so I understand most of the theory behind it all. What I'd like to do now is take that knowledge I have and put it into practice in the form of some small applications.
I've been reading through some articles on MSDN on how to do this, but they seem to only cover network programming at layer 3 or 4 and upwards, IIRC. What I'm looking for is some simple examples of how to deal with layer two connectivity (ie. framing) between hosts, or even just something simple like how to perform an Ethernet broadcast.
I have a little experience with C# and C++, so examples which use either of those languages would be great.
Thanks.
For Windows, have a look at WinPcap which provides low-level network access. The developer pack already contains some simple examples to get you started.
BTW, on Linux there are packet sockets.
You could use the eEx Network Library to write small apps (I have done the same thing during my CCNA).
It is an easy-to-use and object-oriented .Net programming library, which lets you go down to layer 2 and send out custom frames via WinPcap.
Frame types like Ethernet, ARP, IP, UDP, TCP and RIP are implemented, and as far as I know, these are protocols which occur during CCNA.
Tutorials in C# are available here, and if you want look at something in depth, like address resolution, you can always have a look at the source code, since the library is open source.
Very probably, you could study low-level network utilities on GNU/Linux systems, or also look into the kernel TCP or UDP or IP layers. But for instance, doing an Ethernet broadcast is something very low level, and not very useful. And real examples (usually coded in C, not C++) probably can't be simple because they have to deal with error handling.

(lightweight) Instant Messenger: C#.Mono, node.js or other?

Which programming language should I use to write an Instant Messenger?
Here are the goals:
should be able to handle many, many users (at least for proof of concept)
protocol should be based on json or maybe binary data. i guess json is easier to implement and extend. I don't want to use XML because of the overhead. I know it's not much data but it should be as fast as possible especially on slow networks (e.g. mobile).
users should be able to be logged in on multiple devices simultaneously
history should be saved server sided so it can be viewed on all devices
server should keep a lot of idle clients alive
file transfer (not quite sure on how to realize, maybe a different network socket so it does not block chat messages on client side)
MySQL auth
(No, XMPP is not an option).
I'm a web developer with good experience in PHP but that is not an option for this project. I also have experience with Javascript (mainly for websites), but it would be easy for me to work with node.js and I have little experience with C#.Net and could also write C#.Mono. The server I want to write should run on Linux. I have no experience with Java but if it's the best way I could learn it.
I've read much about node.js and that it's evented I/O is really good for network applications and web servers. But what about instant messengers? The main part is to save messages and proxy them to the other room participants, so it's "network".
I also thought about C# which offers asynchronous sockets which work with a thread pool afaik instead of a event queue.
I'm not sure which of them is most efficient in regard of an IM server.
It would be nice if someone could give me a hint. I know C++ would probably be the best way but I somehow don't really like that language and it's hard to learn.
You can do all this in any normal programming language (C#, Java, C++, etc...), as long as you're competent enough in that language.
Any of those solutions will do. You can write evented networking code in pretty much any language - and yes, it's pretty cool to use it in scenarios like this one.
If you want something that will give you some kind of framework for easier networking, I'd recommend trying Erlang, but it might be tough to learn for a single project. node.js might be tricky with regards to keepalives / resource management on dead connections and similar scenarios where you don't really get an event.
If you're already familiar with c#, using mono might be the safest / fastest thing for you. Apart from that - you can write anything in any language - just use what you're comfortable with (unless you actually want to learn something new).
I don't know why you wrote that jabber isn't an option, but if it's only the xmpp technology you don't want, why not use a typical SIP proxy/server? (for example OpenSIPS) It's got MESSAGE request handling, subscriptions, authorization (with db) and keepalives already available. You can scale / cluster / shard OpenSIPS in pretty much any way you want.

Categories