No video

C# Async Sockets Part 1: Basics

  Рет қаралды 48,176

Brian

Brian

Күн бұрын

The foundation of asynchronous TCP client/server project. Find the source here:
github.com/Abl...

Пікірлер: 47
@louisvantonder5068
@louisvantonder5068 5 жыл бұрын
7 years later and this is a far better explanation on async sockets than I could find in Microsoft Dev articles! Stripped of all the frilly nilly normal Microsoft bells and whistles. Just the basics, so one can see what the heck is happening. Job well done from the future here... ;-)
@dwestley74
@dwestley74 6 жыл бұрын
Good Tutorial. Per other comments, "Basic" is relative but I though your program showed the fundamentals of Asnyc TCP socket communication. I looked at several other tutorials but this one was very clear and easy to follow. Thanks!
@viruxer
@viruxer 9 жыл бұрын
Thank you so much. This was exactly what I needed. Msdn sometimes doesn't cover everything.
@Sendeos18
@Sendeos18 11 жыл бұрын
I really like how you explain each line I am here to learn not to copy/paste,so many other videos people just writing code... Thanks great video big help! subbed
@Crashid3D
@Crashid3D 8 жыл бұрын
As a hint, there is a method overload of System.Encoding.ASCII.GetString() that takes a bytesIndex and a bytesCount parameter, so you don't have to resize your buffer every time you receive something.
@justinlynch6691
@justinlynch6691 6 жыл бұрын
Colonel Panic how would anyone know that?? That's what I find so difficult about c#
@Dennis19901
@Dennis19901 5 жыл бұрын
It's also not a good idea to resize the receive buffer every-time you receive something. Handle the message and simply let the buffer get overwritten. Resizing an array means it gets copied to a new, smaller array. This is a rather expensive operation to do every-time you receive data.
@woollerland
@woollerland 11 жыл бұрын
Thanks for reply. I understand how async socket function now, cheers.
@KneesBitten
@KneesBitten 7 жыл бұрын
Basic is a relative term, perhaps. I like the video alright, but to keep it on basics, it may help to explain what the purpose of the parameters are as you pass them. For instance, when you're giving the callback function the IAsyncResult, what is going on in there. That is to say, this is a good tutorial for people who already have a partial understanding of Sockets, but need help in filling in those gaps in their understanding.
@sanfordhoffman2392
@sanfordhoffman2392 7 жыл бұрын
Boh I totally agree. I think ill revisit this when I'm a more advanced programmer in sockets. It may become crystal clear. Until then ill go shop for a intro level tutorial. I don't consider myself a beginner in c# programming by a long shot. Just a beginner in this subject. I understand the concepts of sockets on an IP network. If the author explained it better, I'm sure i would catch it. Going to hunt for that author now. He/She isn't here. Kudos to Brian from being a big brain. Wish he could have conveyed some of that awesome talent to mere mortals.
@luisalbertohernandezorante3481
@luisalbertohernandezorante3481 10 жыл бұрын
Thank you very much my friend, just what I was looking for :D
@LeftTechticle
@LeftTechticle 12 жыл бұрын
Wow, good to know, it is a bit tedious on my end, I have to wait for windows to try to fix the solution, then pick how I want to debug. But will save me a lot of effort
@user-mb4nj2tg4f
@user-mb4nj2tg4f 3 жыл бұрын
شكراُ لك
@kandlbecker
@kandlbecker 7 жыл бұрын
Unlike some of the other commentors, I found the code in this example much more understandable than, say, the Microsoft example here: msdn.microsoft.com/en-us/library/fx6588te(v=vs.110).aspx. I ran some high school students through basic C# tutorial, and they were able to get a socket connection up and running. Yes, it does require a certain degree of solid C# understanding, but I wouldn't call it "advanced knowledge."
@LeftTechticle
@LeftTechticle 11 жыл бұрын
Yea ive done multiple connections with a client list in async. I create an abstracting client class with the client socket and name. and yes the async internal and callback methods run on their own thread(s). I'm not sure about the first question, there's no such thing as IAsyncCallback... I can tell you a bit about how the async methods and callbacks work if that's what you mean
@LeftTechticle
@LeftTechticle 11 жыл бұрын
Yes, thats how sockets work. The sockets are endpoints, they are near identical. Just use the socket for the client and not the server. The server socket is just for listening.
@LeftTechticle
@LeftTechticle 11 жыл бұрын
Im relearning socket programming right now so it should be made soon as well I figured some stuff out that will help me make DevBox run smoother which should be cool
@007faarax
@007faarax 11 жыл бұрын
Thanks Alot. I really enjoyed the video.
@simbaorka101
@simbaorka101 8 жыл бұрын
Hey, I was wondering, socket.listen() is supposed to say how much people can be queued at one point, so you said you set it to a default value of 0. Does that mean there is basically no queue or?
@80amnesia
@80amnesia 5 жыл бұрын
thanks
@sanfordhoffman2392
@sanfordhoffman2392 7 жыл бұрын
Very cool. Too bad you didn't explain it better for us that are new to Socket programming in general. I guess it was the word "Basic" in the title that threw me. Basic to Sockets? But experienced in what all those classes do? Good try Brian. It really looks like you know what you're doing. Sad that you aren't conveying the details to your audience.
@user-hd8tg4em2n
@user-hd8tg4em2n 7 жыл бұрын
I've been programming for almost a decade and I've never seen someone so ungrateful. Go to MSDN and read up on the functions used, or read about the TCP/IP model. He is giving you free information, appreciate it and learn from it.
@sanfordhoffman2392
@sanfordhoffman2392 7 жыл бұрын
Paper Plane Thank you for your opinion. I’m aware of the TCP/IP model. Maybe the experience level on the video was out of my current range of knowledge. I frequently go to MSDN for information already. I wasn’t questioning the presenters skill. It was just over my head for a “basic” course. I’ll look elsewhere and see if i can find something even more basic. My intention wasn’t to offend anyone. Just to convey the fact that it was a bit more advanced than anticipated for a basics course. At least for me. Sorry i was the highlight of offense of a long career such as yours.
@sanfordhoffman2392
@sanfordhoffman2392 7 жыл бұрын
Paper Plane If you read further down the comments, i am not the only one who thought it was too much for the basics.
@lyozov974
@lyozov974 6 жыл бұрын
Welcome to the internet, the place full with ungratefull basterds!
@noahguillen7939
@noahguillen7939 5 жыл бұрын
Bruh just chill out lmao 😂😂
@woollerland
@woollerland 11 жыл бұрын
Am i correct in thinking that using IAsyncCallback is similar to the interupt concept where if an item changes, the system automatically responds to that change independent to whats been processed so in this system, when a socket has requested from client, it manages the socket independently to what the main thread is doing? If this is so, if we put all active client sockets in a array/list, we can allow multiple connections?
@richardmulawa2635
@richardmulawa2635 8 жыл бұрын
I have a project where I have a test box that has 34 boards and each board is a server. I need to create a client that checks to see which of the 34 boards is available and then connect tcp and send a cmd to read the status of the boards. I need to poll these boards continuously. This need to continuously poll is causing me no end of grief!!! I cannot afford to sit for nearly a minute and wait for timeouts should a board be down or unavailable and of cannot find any examples of how to continuously poll servers as fast as possible and handle unavailable connections.
@paulart119
@paulart119 9 жыл бұрын
Hey, loved the name!!! Very useful Async socket stuff but unfortunately I am not able to access the sample code. The code I used from Part-1 ran beautifully but the second part is throwing some exceptions - at the part where I close client and open another one - i get "Cross Thread Opeartion not valid Control btnsnd accessed from a thread other than the thread it was created on" ........don't know what I am doing wrong. Any help would be great
@LeftTechticle
@LeftTechticle 11 жыл бұрын
hey man, got a lot to do on my non network based stuff, so I will be bogged down for a while, when I can I will make the video
@LeftTechticle
@LeftTechticle 11 жыл бұрын
No, but Ill try to make it soon, I just have to fix my sticky note app
@sbasalan
@sbasalan 10 жыл бұрын
I cannot see this tutorial's link to get it at that link that you given.
@gameking008
@gameking008 12 жыл бұрын
ctrl f5 still shows the exception messages.
@007faarax
@007faarax 11 жыл бұрын
hi, what about if the server sends a data, does the client uses the same connection to receive?
@hasansahin1977
@hasansahin1977 5 жыл бұрын
thank you for sharing. can the code on the server be easier than the following though? void ReceiveCallback(IAsyncResult AR) { int byte_count=client_socket.EndReceive(AR); string txt = Encoding.ASCII.GetString(_buffer).Remove(byte_count); AppentToTextBox(txt); client_socket.BeginReceive(_buffer,0,_buffer.Length,SocketFlags.None,new AsyncCallback(ReceiveCallback),null); }
@Dennis19901
@Dennis19901 5 жыл бұрын
Yes, you only need the EndReceive and the BeginReceive (provided that you want to receive more data). All the rest you do in between is up to you.
@RobertoLion
@RobertoLion 3 жыл бұрын
Does this work for multiple PCs at once (multiple clients)?
@LeftTechticle
@LeftTechticle 12 жыл бұрын
I don't notice it
@paulart119
@paulart119 9 жыл бұрын
Cancel that previous question from me - I did not see the thread safe call to btnSnd in part-2, once that was included this problem went away.
@Sendeos18
@Sendeos18 11 жыл бұрын
:)
@LeftTechticle
@LeftTechticle 11 жыл бұрын
Disregard that last comment, thanks
@LeftTechticle
@LeftTechticle 11 жыл бұрын
Its not really a beginner vid
@subz3r041
@subz3r041 8 жыл бұрын
lol
@ctbram0627
@ctbram0627 9 жыл бұрын
Basics? I guess this is the "basics" of async sockets but it was not a "basic" tutorial. I felt like you assume the viewers have a great deal of advanced c# programming knowledge. callbacks that are "not quite" call backs, and method invokers, ...., by the half way point you may as well have been speaking latin
@ZintomV1
@ZintomV1 6 жыл бұрын
ctbram0627 If you were looking to learn C# look at a C# tutorial not an Asynchronous Socket programming tutorial.
@AlekseyCLX
@AlekseyCLX 7 жыл бұрын
A lot of bad-practices was demonstrated in this "basics". Not recommend to go this way.
@Shadow4707
@Shadow4707 7 жыл бұрын
As somebody who wants to learn this stuff, your comment doesn't help me at all. What exactly is bad practice here?
C# Async Sockets Part 2: Robustness
9:48
Brian
Рет қаралды 13 М.
C++ Network Programming Part 1: Sockets
1:13:52
Nicholas Day
Рет қаралды 116 М.
Parenting hacks and gadgets against mosquitoes 🦟👶
00:21
Let's GLOW!
Рет қаралды 12 МЛН
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 35 МЛН
Harley Quinn's plan for revenge!!!#Harley Quinn #joker
00:49
Harley Quinn with the Joker
Рет қаралды 32 МЛН
C# Network Programming: Create a Multithreaded Client-Server Application
21:00
Socket in C#
50:18
Benny Jørgensen
Рет қаралды 21 М.
TCP Socket Tutorial (C#, Visual Studio, Networked Console Apps)
16:24
wolfs cry games
Рет қаралды 56 М.
Rust and RAII Memory Management - Computerphile
24:22
Computerphile
Рет қаралды 224 М.
Malware Development: Processes, Threads, and Handles
31:29
C# Events and Delegates Made Simple | Mosh
32:04
Programming with Mosh
Рет қаралды 940 М.
C# Tutorial - SuperSimple TCP/IP Client Server | FoxLearn
23:11
Fox Learn
Рет қаралды 111 М.
Parenting hacks and gadgets against mosquitoes 🦟👶
00:21
Let's GLOW!
Рет қаралды 12 МЛН