The foundation of asynchronous TCP client/server project. Find the source here: github.com/Abl...
Пікірлер: 47
@louisvantonder50685 жыл бұрын
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... ;-)
@dwestley746 жыл бұрын
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!
@viruxer9 жыл бұрын
Thank you so much. This was exactly what I needed. Msdn sometimes doesn't cover everything.
@Sendeos1811 жыл бұрын
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
@Crashid3D8 жыл бұрын
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.
@justinlynch66916 жыл бұрын
Colonel Panic how would anyone know that?? That's what I find so difficult about c#
@Dennis199015 жыл бұрын
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.
@woollerland11 жыл бұрын
Thanks for reply. I understand how async socket function now, cheers.
@KneesBitten7 жыл бұрын
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.
@sanfordhoffman23927 жыл бұрын
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.
@luisalbertohernandezorante348110 жыл бұрын
Thank you very much my friend, just what I was looking for :D
@LeftTechticle12 жыл бұрын
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-mb4nj2tg4f3 жыл бұрын
شكراُ لك
@kandlbecker7 жыл бұрын
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."
@LeftTechticle11 жыл бұрын
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
@LeftTechticle11 жыл бұрын
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.
@LeftTechticle11 жыл бұрын
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
@007faarax11 жыл бұрын
Thanks Alot. I really enjoyed the video.
@simbaorka1018 жыл бұрын
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?
@80amnesia5 жыл бұрын
thanks
@sanfordhoffman23927 жыл бұрын
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-hd8tg4em2n7 жыл бұрын
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.
@sanfordhoffman23927 жыл бұрын
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.
@sanfordhoffman23927 жыл бұрын
Paper Plane If you read further down the comments, i am not the only one who thought it was too much for the basics.
@lyozov9746 жыл бұрын
Welcome to the internet, the place full with ungratefull basterds!
@noahguillen79395 жыл бұрын
Bruh just chill out lmao 😂😂
@woollerland11 жыл бұрын
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?
@richardmulawa26358 жыл бұрын
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.
@paulart1199 жыл бұрын
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
@LeftTechticle11 жыл бұрын
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
@LeftTechticle11 жыл бұрын
No, but Ill try to make it soon, I just have to fix my sticky note app
@sbasalan10 жыл бұрын
I cannot see this tutorial's link to get it at that link that you given.
@gameking00812 жыл бұрын
ctrl f5 still shows the exception messages.
@007faarax11 жыл бұрын
hi, what about if the server sends a data, does the client uses the same connection to receive?
@hasansahin19775 жыл бұрын
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); }
@Dennis199015 жыл бұрын
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.
@RobertoLion3 жыл бұрын
Does this work for multiple PCs at once (multiple clients)?
@LeftTechticle12 жыл бұрын
I don't notice it
@paulart1199 жыл бұрын
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.
@Sendeos1811 жыл бұрын
:)
@LeftTechticle11 жыл бұрын
Disregard that last comment, thanks
@LeftTechticle11 жыл бұрын
Its not really a beginner vid
@subz3r0418 жыл бұрын
lol
@ctbram06279 жыл бұрын
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
@ZintomV16 жыл бұрын
ctbram0627 If you were looking to learn C# look at a C# tutorial not an Asynchronous Socket programming tutorial.
@AlekseyCLX7 жыл бұрын
A lot of bad-practices was demonstrated in this "basics". Not recommend to go this way.
@Shadow47077 жыл бұрын
As somebody who wants to learn this stuff, your comment doesn't help me at all. What exactly is bad practice here?