This is the simplest way I could do it. Find the code here (it's a bit more organized): github.com/AbleOpus/Networkin... BTW: Use Buffer.BlockCopy() same syntax but faster
Пікірлер: 277
@fanuelinawgaw20658 жыл бұрын
That was awesome! Not only did you help me get a better understanding but you also made me go further, so thank you very much!
@fletchercutting94409 жыл бұрын
Thanks for the awesome tutorial. I'm currently designing a multiplayer hacking simulator which I will now be able to program thanks to this tutorial :) It's basically just going to be command based where the client types in commands and the commands, clients and other data is dealt with in the server. Thanks a heap :D
@waszqba3 жыл бұрын
Your source helped me a lot with my uni project, made me kinda understand how to use C# implementation of sockets and how to serialize data for that. Not all heroes wear capes, thank you.
@alessandrogerelli7 жыл бұрын
Great job. You just saved my life and teaches me something fantastic.
@harunmn7 жыл бұрын
i was trying to learn about socket programming and this video is awesome, just watched once then i wrote my own server and client. thanks for sharing....
@tahacyberman36409 жыл бұрын
THAT was AWESOME (Y) really thank you man, you are very pro brother, thank you , that was what I was searching for it for about 2 weeks (Y) THANK YOU
@squirekev3 жыл бұрын
4:30am testing, ah the exciting life of a programmer. few minutes off from when I'm watching to attempt a similar objective. Nice tutorial. Verbalizing as you worked away was very helpful in understanding the reasoning for your choices.
@MrHogarth4510 жыл бұрын
Hey thanks for the video, I've just decided to get into network programming and this is a great introduction.
@Krypton913 жыл бұрын
Thank you for this Tutorial! Very usefull to understand how sockets work in C# :)
@tgifhounds10 жыл бұрын
You are one of those guys people stand behind and watch code, great tutorial.
@jubin4joy10 жыл бұрын
Thanks a lot dude, it was something new from my experiance.
@ajitkumar1510 жыл бұрын
Great Video.. you are a great programmer .I am big FAN of yours. Thanks for this video...it helped me to understand our company project which is also using socket programming.
@stutitehri99310 жыл бұрын
superb tutorial;used to be scared abt socket programming
@nickcsgo10 жыл бұрын
YES YESS YESS TY TY THIS IS EXACLTY WHAT I WAS LOOKING FOR PLZ TY
@randomasshandle22310 жыл бұрын
Thanks a lot dude! Very easy to follow along, you spoke clearly, and explained what each method did. A++ would recommend.
@vukasinvucenovic901510 жыл бұрын
Would be bad if you gave him C++. HAHAHA dem programmer jokes....
@LeftTechticle10 жыл бұрын
Vukasin Vucenovic lol
@bestefarm99667 жыл бұрын
Thank you so much for this tutorial! Great work! :-)
@cristianokwiatkovsk90594 жыл бұрын
very good job, i used this in my study
@Inzolity8 жыл бұрын
This is pretty neat, thanks!
@jeelpatel98184 жыл бұрын
thank you very much. Really nice explanation
@sayalisurve58013 жыл бұрын
You are amazing!! thank you so much
@Crni036 жыл бұрын
Great tutorial! Thanx a lot!
@LeftTechticle11 жыл бұрын
Ya, if your clients disconnect ungracefully, you can get exception in various points of the server. You need to handle these errors and remove the client form your client list when they occur for a specific client.
@user-ci9ny8vo7b5 жыл бұрын
Thx bro I am Taiwanese love your video a lot
@AbbasKhan-qu7ib7 жыл бұрын
well it is such a great help thank-you and keep it up (Y).
@LeftTechticle11 жыл бұрын
Its in my best interest to disregard byte accumulation for this video. And I dont know what you mean with the callbacks. And by the way, I will have another vid on receive past buffer size which will be much more robust than the other one.
@b4ux1t3-tech9 жыл бұрын
Excellent job teaching Sockets. Though, I would have preferred if you took time to comment your code. Not because it necessarily needs comments (though they might help explain things a bit better) but more because otherwise you go very fast! I had to pause and go back several times. Still, learned more about working with sockets tonight than I ever did trying to read the docs.
@LeftTechticle9 жыл бұрын
Indeed, I am going to get around to the source and apply comments to it at least. I've been refactoring everything.
@__-qe7pl4 жыл бұрын
hello your great tutorial is so good. this video i can solve my problem. Thanks a lot!
@binishvbabu3 жыл бұрын
Thanks for the video!
@chiennguyen-un5wx8 жыл бұрын
Thanks u so much! ^^ it usefull for me!
@giaple112310 жыл бұрын
Hey! Just wanna say thank you very much! :)))
@EbbsClifton334 жыл бұрын
This was great, thanks
@chrisschuller70553 жыл бұрын
Excelent Tutorial!
@sadfjlkjsdivje7 жыл бұрын
Thanks for the video:)
@panagiotisgnafakis98519 жыл бұрын
Hey man, your tutorial is awesome and I did understand it. I have one problem though, if I try to send data from another computer in the network it doesn't work. I try to change the listening IP to a specific IP and it only accepts connections that come from my computer's IP. If I try to send anything through the network, i.e. from another computer either A) it does't see the data coming (when socket is bound to "IPAddress.Any") B) it crashes at server setup (when socket is bound to an external (LAN address)) Do you have any idea on what is wrong?
@Nz_Yhwach5 жыл бұрын
My god, u help me a lot
@Levonfly3 жыл бұрын
Thank you!
@jaycelee84532 жыл бұрын
Thank you. :)
@borissman8 жыл бұрын
THANK YOU!!!!
@Tibiafy4 жыл бұрын
Thx man! U saved my life haha
@RMDetho8 жыл бұрын
Greetings @LeftTechticle , I liked your video and I liked your example even more. I hope you don't mind me asking you this.. I'm working on a multiplayer card game (just to learn, no specific reasons) and I stumbled upon your video trying to find a solution to server/client connections. In your example, the client is just as is on the server, in other words, server doesn't care who the client is.. but is there a way to differentiate separate clients? or send sort of an object containing information about the specific client to the server?
@Gildo20210 жыл бұрын
Thank you very much.
@GuillinCorp8 жыл бұрын
Thanks fam appreciate
@LeftTechticle11 жыл бұрын
I learned from initially books and now c# articles.
@bluepole4216 жыл бұрын
can you do it also in C# windows server and client.?
@fletchercutting94409 жыл бұрын
If you want to fix the error when the client disconnects, replace the code in the ReceiveCallback function with this: Socket socket = (Socket)ar.AsyncState; try { int received = socket.EndReceive(AR); byte[] dataBuf = new byte[received]; Array.Copy(_buffer, dataBuf, received); string text = Encoding.ASCII.GetString(dataBuf); Console.WriteLine("Text received: " + text); if (text.ToLower() == "get time") { SendData(DateTime.Now.ToString(), socket); } else { SendData("invalid request", socket); } } catch { Console.WriteLine("client disconnected"); socket.Close(); socket.Dispose(); }
@bigbolo19868 жыл бұрын
thanks for this!!!
@firstnamelastname78446 жыл бұрын
What's the SendData function?
@SuperChristianMiiworld6 жыл бұрын
Where the f**k did that SendData function come from?
@dievel52566 жыл бұрын
tank you ^^
@lucasgrizante11656 жыл бұрын
If a client disconnect, should I remove him from _clientSockets list? also, if I'm creating a game (just for example) with a login screen and etc, I'd have to call the "loopconnect" at the login button? Also, how can I force a client to disconnect (and make him know that he has been disconnected)? I'm thinking about just calling something like _clientSockets[0].Close(), _clientSockets[0].Dispose(), _clientSockets.remove(0); but I don't know what would happen with the client at this point. Also, thanks for your fix!!
@AcEPFL10 жыл бұрын
In order to stop it closing you have to add Console.Readline(); in the Main. Make sure it is your last code in the Main.
@LeftTechticle11 жыл бұрын
I know exactly what you mean, but I left them things out for the sake of the concept
@russiansoldiersniper41836 жыл бұрын
i love
@norge_daniel4 жыл бұрын
Hi Brian. Congratulations.Good tutorial !! Do you have some example from this point to implement WebSocket Server in C# using Socket ?
@varunjain06068 жыл бұрын
Hi, Nice tutorial. Learned a lot from the video. However I have a doubt as to how can we handle the request based on timer...means I want to disconnect the socket connection if i don't get response from any client. May be 5 seconds for instance and the time for each client starts from the moment they are connected and whenever they send response, the particular timer for the client resets to 5 secs. Thanks.
@LeftTechticle11 жыл бұрын
If you mean to type it out as the video goes then yes. I dont induce that
@penguthepenguinj5 ай бұрын
Amazing
@LeftTechticle11 жыл бұрын
Its probably not a good idea to try to predict where threads are spawned in Async methods. Just know whether you on a UI thread or not (print out your current thread IDs or something to see). BTW this vid is not meant to explain the behavior of anything, it was just to present a simple design pattern for multiple clients.
@justchris8465 жыл бұрын
if the ports specified in code don't work, then set the port's number higher than 1024, I forget if port 100 is used by the system or not, but there are a LOT of open ports available, excellent tutorial tho!
@ThePreceptIsInCSharp6 жыл бұрын
can it work like a public server I meant can it send a message to one computer from a remote computer?
@jayelliott16 жыл бұрын
Hello Brian. I'm interested in executing OS commands on multiple servers in parallel ..ie to stop and start applications on all servers at once. I'm using VS Studio WPF C#...also considering integrating python or windows powershell, but hope to use C# only...do you have any tips? Will the method of programming sockets in your video work? I'm new...please share tips?
@LeftTechticle11 жыл бұрын
Well the Speech namespace does not provide freeform dictation, but you can try to load an entire English dictionary as grammar. You would then perform tests on the results like anything else. This is a long shot though
@r.gianfrancocarbonells.96625 жыл бұрын
Thanks!
@LeftTechticle10 жыл бұрын
I think using the Socket class would be the best. Theres abstractions like TcpClient and TcpListener that don't seem to make anything easier. I cant tell you if it would be appropriate to adapt the sample. The sample wont be able to retrieve large amounts of data. As well its better just to put all of this stuff in a class library if it were any more complex than this.
@WelshGuitarDude7 жыл бұрын
Would this stuff be used to make server FPS stuff or is this more for things that doesn't require fast updates?
@tomasmartins50097 жыл бұрын
How would you go about checking everyone who's connected to the server and sending messages from the server to any client at any given time, not just as a response to a request from a client. Sort of a push notification.
@usergroupX9 жыл бұрын
ah , no need to convert port's byte ordering like in c++ ...you know why I don't neeed glasses? because I can C # .. lol
@tyrellwreleck42266 жыл бұрын
i have no idea what you said about c++, im no c++ literate but i like your joke :)
@Chiramisudo6 жыл бұрын
Wait, does that mean I can't C# because I do need glasses?... but I can C#. It's a paradox!
@mreazl62274 жыл бұрын
Lmao
@LeftTechticle10 жыл бұрын
Are you looking for suggestions on creating a chat program?
@DaGoofSta6 жыл бұрын
Everyone who wants to send the time to all clients at once you would need to loop through the socket list sending it to all at once for instance List socketList = new List();//Will be full of connected clients foreach(Socket s in socketList) { byte[] data = sendString("time string here"); s.Send(data); } public byte[] sendString(string msg)//method for converting bytes into strings { byte[] data = Encoding.ASCII.GetBytes(msg); return data; }
@martinhschei64866 жыл бұрын
Nice tutorial! But why make the buffer static? All recevied data from clients will then be put in the same buffer.
@HonnerApl7 жыл бұрын
I have a doubt, running this with many clients, using the same static buffer won't make the requests get all mixed?
@AbbasKhan-qu7ib7 жыл бұрын
i have done the same code and it worked fine. i made some changes like from server side i changed responce on switch(text) and it worked well but when i tried to read() some responce from serverside, on run time it throws exception of socket , at int rec = _clientSocket.Receive(recievedBuf); if someone can help ???
@LeftTechticle10 жыл бұрын
There are a lot general things I could say but not too much about receive and store information. I can give you general advice.but only through voip, preferably skype
@kimy54806 жыл бұрын
Hello! How can I allow connections from clients outside of my local network?
@rogernevez51878 жыл бұрын
Excellent! Do you know if it is possible to do a raw socket in win7?
@nimda40472 жыл бұрын
Nice video, now the following question occurs to me; if i want to send a message from one client to the other(s) via server (client1 -> server -> client2), do i just use a loop and count through all the connected client sockets like "clientSockets[i].Send(data); i++;"
@dorinelnicolaerus353310 жыл бұрын
The idea is that the boards read some sensors, after that the data is processed by the firmware within the micro-controller and than is sent using Ethernet protocol to the server. Another situation is when I send from the server a command and the firmware within the micro-controller will process it and do a different task. So my question is whether the video that you presented can be adapted to do this, because I think that I must to use the same Socket class.
@alpharomeo51236 жыл бұрын
Good!
@siavashmehmandoost21983 жыл бұрын
Thanks for this amazing tutorial! Is this applicable on Unity? I set client code on unity, But when I ran server on pc it didn't work
@madalinmironica36264 жыл бұрын
sei un parolaio
@theldentity7 жыл бұрын
My visual studio says that Socket does not contain definition for BeginAccept help please. Tried in windows forms and actually works
@JMemini810 жыл бұрын
Great Tut. I Learned something. But sir, why my client side only can request one time only? an also I tried with my two laptops connected to one router but the client cannot connect to server? Please response as soon as you got time. Thanks
@sbasalan10 жыл бұрын
How about out of loopback IP usage of your project? Because I did a project but it can only run as loopback IP(127.0.0.1)
@FranciscoJBurtin5 жыл бұрын
Hi, Why you didn't develop you server in WCF fullduplex service?
@dmccalldds3 жыл бұрын
How did you add a second Client at 26:30?
@gottogetbig29007 жыл бұрын
What does the buffer do? What happens if you dont use a buffer?
@LeftTechticle11 жыл бұрын
Start by establishing whether or not the server is crashing or not.
@bulldoggin1210 жыл бұрын
I need to construct a server which can receive/store the information in a "friends list" from a client for a chat program. Do you have any suggestions?
@ninjasquidface9 жыл бұрын
How come mine stops receiving from a client when the receive callback is called? I mean to say it only works if I put the beginreceive command at the end of the receive callback, is this normal?
@nealdorelis5703 Жыл бұрын
Nice! Can you connect this short client/server app with a database ??
@Mabox-sc5iz Жыл бұрын
I don't know if you don't pay attention but is there something for when a socket is disconnected? Because when I close a client the server crashes
@tyrellwreleck42266 жыл бұрын
why didn't you make a separate class for the client? just wondering
@arthurmillerl10 жыл бұрын
DUDE, YOU ARE A LEGEND.
@Mystic0Dreamer6 жыл бұрын
This works fine when I run the client and server on the same computer. But when I run them on two different computers they never connect. These are computers that are connected via WiFi in my home and can share files. So why isn't this working? Do I need to specify IP addresses?
@JulioPoloArias10 жыл бұрын
Likes++;
@zeekloft11 жыл бұрын
Normally people use PascalCase for methods but camelCase for variables and such.
@DaminGamerMC2 жыл бұрын
what resources could I use to learn about programming stuff like this?
@wolftech13899 жыл бұрын
nice
@agustawicaksono8 жыл бұрын
I tried this code, and it works... but somehow. the server stops listening and i got this. "The thread '' (0x1768) has exited with code 0 (0x0)." Any helps?
@newbienewbie48238 жыл бұрын
i get this error for int received = socket.EndReceive(AR); unhandled exception: system.nullreferenceexception:object reference not set to an instance of an object.
@sybangnguyen858210 жыл бұрын
A++
@koblar_9 жыл бұрын
How to send message from server to client? I wanted to create server and client in one application (listening and writing), but it doesn't work. There must be something I'm doing wrong... can you tell me what I need to do to send message from server to client?
@JesusChrist-tt1sz9 жыл бұрын
If you want to get rid of the error that occurs when the client gets closed you need to use a try catch around where you get the exception.
@LeftTechticle9 жыл бұрын
Jesus Christ Ye, gotta catch them all
@ellywithpluto1257 жыл бұрын
This help me alot problem with TCP, Console.Write("Thank you !")
@JohnDoe-rw8he6 жыл бұрын
You forgot the semi-colon
@michaelepica35644 жыл бұрын
*Console.WriteLine("Thank you!");
@TuNguyen-zw9dv10 жыл бұрын
could you please send me the code of these solutions? i can't find them in your attached link. thanks a lot
@LeftTechticle10 жыл бұрын
I can help with specific things for sure, but if your boards do not run .NET, then I would have little idea how to process the request.