Creating a TCP Server in C++

  Рет қаралды 323,808

Sloan Kelly

Sloan Kelly

7 жыл бұрын

#networking #sockets #tcpip #cplusplus
This is an introduction to network programming by building a server that echos the client's messages back. The server is written in C++.
Having problems? • Finding Out Why My C++...
Get it working in LINUX: • Creating a TCP Server ...
If you're looking for a backgrounder on networking, sockets, ports etc. Check out the companion video here: • Introduction to Networ...
You'll need PuTTY to test out the server. It can be downloaded from here: www.chiark.greenend.org.uk/~sg...
Full source can be downloaded here: bitbucket.org/sloankelly/yout...

Пікірлер: 564
@RaZziaN1
@RaZziaN1 4 жыл бұрын
For people with error "invalid padding length" instead of using SSH in puty, use RAW.
@Gavy093
@Gavy093 4 жыл бұрын
If I may ask ...How did u figure that out?
@sirgouki6207
@sirgouki6207 4 жыл бұрын
@@Gavy093 I figured it out before I saw this comment, just by random testing. Fun fact: both PuTTY telnet and Windows telnet will *immediately* send your keys to the server, which will *immediately* send them back, which looks like your telnet client is messing up.
@ericc5652
@ericc5652 4 жыл бұрын
WOW...Thank you very much!
@alexanderwilson5659
@alexanderwilson5659 4 жыл бұрын
it works!!
@gangelo2787
@gangelo2787 4 жыл бұрын
Humm. This isn't really a "fix" if you want to maintain a secure connection. I wonder how to actually fix this.
@kidkyle712
@kidkyle712 3 ай бұрын
7 year old video and still one of the best resources on this topic I could find. Amazing.
@sloankelly
@sloankelly 3 ай бұрын
Glad it was helpful!
@heavymetalmixer91
@heavymetalmixer91 26 күн бұрын
Why do you think it's the best? I'm just starting with programming in general and C++ specifically so I don't know anything about other "better options".
@kidkyle712
@kidkyle712 25 күн бұрын
@@heavymetalmixer91 I just think the structure of the video is well done. Instead of jumping right into coding he first lays the steps out, otherwise you’d be enticed to just type over without thinking of the ‘bigger picture’ of what is actually being achieved. He also does this in the code with comments instead of a decoupled slideshow for example. That way you won’t have to go back to check the steps as they are there plus it chains the ‘theory’ and practice together.
@benficapedro2
@benficapedro2 5 жыл бұрын
OMG been seeing so many tutorials and so many hours spent on this, and ONLY AFTER WATCHING THIS VIDEO, IT'S WORKING!!!!!!!! Thank you, you really helped me :D
@agentk3984
@agentk3984 4 жыл бұрын
Comment the entire thing, THEN code it. That is the definition of professional sir, a true professional expert...
@choosetolivefree
@choosetolivefree 3 жыл бұрын
I'm not a professional in that I am self taught and work for my self and not some big company.. but I'm pretty sure actual professionals use flow charts to outline their applications. Not saying the comment method isn't good, but flowcharts are definitely superior.
@choosetolivefree
@choosetolivefree 2 жыл бұрын
@ASRDGEEK I mean, that's how I operate, I just step through each step of what I want the app to do, and then code it.. but I code solo. What about teams of developers? How does anyone know what each other are doing without some sort of outline?
@DeniseJamestoo
@DeniseJamestoo 6 жыл бұрын
Great video and the comment on setting putty to raw. I got this working in one hour. This is my first ever socket application.
@darkchocolate3390
@darkchocolate3390 5 жыл бұрын
How did you connect to Putty? I put my ip address I found in cmd but it didn't work.
@PM-et6wz
@PM-et6wz 7 жыл бұрын
Always wanted to do something like this in c++ but had no idea where to start. So thanks a lot and awesome video.
@theshawnz
@theshawnz 4 жыл бұрын
Sloan, thank you for the video , extremely helpful for a project I have been working on.
@jackbailey049
@jackbailey049 2 жыл бұрын
The amounts of stuff you can learn through youtube! Thank you
@gayashanrathnavibhushana2615
@gayashanrathnavibhushana2615 5 жыл бұрын
Thank you for this video series. It helped me a lot..
@licknelon3076
@licknelon3076 6 жыл бұрын
Nice, a fellow Scotsman. Thanks for these videos!
@sloankelly
@sloankelly 6 жыл бұрын
I still have my accent! \\:D//
@stevenhine8269
@stevenhine8269 3 жыл бұрын
Thank you very much for explaining this! For those getting the error Can't connect to server code 10061. The repository link above is to the client. You'll have to find the correct bare bones server project.
@sloankelly
@sloankelly 3 жыл бұрын
You might get away with just changing the port number to something else. Another service might be using 54000.
@garyrogers378
@garyrogers378 4 жыл бұрын
Others posting "tutorials" on KZbin should look at this before posting some of the garbage that's on here. This is exemplary work, so well explained and most importantly, Mr.Sloan does not have marbles in his mouth as so many of these sound like! Thanks for taking the time to do a twisted topic a lot of good! Many thumbs up!!!
@omarl7333
@omarl7333 7 жыл бұрын
i using the raw option in putty, work perfect! ty great tutorial
@emperorj4783
@emperorj4783 2 жыл бұрын
Thank you. This really helped me! You are the only one with a good tutorial
@kulaningobeni20
@kulaningobeni20 3 жыл бұрын
Thanks for the time and effort put in this video. It is very informative.
@delysid604
@delysid604 2 жыл бұрын
Thank you mate. Clear explanation all ur steps. Good vid
@brocksprogramming
@brocksprogramming 6 жыл бұрын
I got it working, great video sir.
@dheerajsharma5492
@dheerajsharma5492 5 жыл бұрын
thanks for neat and clean explanation
@usama57926
@usama57926 6 жыл бұрын
Hi Sloan Kelly, your explanation is nice
@wamxfl1p653
@wamxfl1p653 5 жыл бұрын
"I won't cover any error handling from now on. This program won't fail. I think." Lmfaooo
@dinoconsabor
@dinoconsabor 2 жыл бұрын
This was a great introduction to sockets programming for me.
@TheTheThewillow
@TheTheThewillow 2 жыл бұрын
I would recommend checking a video in C and not C++. This is just not detailed and more object oriented
@dinoconsabor
@dinoconsabor 2 жыл бұрын
@@TheTheThewillow at the time they were looking into C++, but I agree.
@swiftsifu
@swiftsifu 6 жыл бұрын
Great tutorial, thank you.
@giuseppe1695
@giuseppe1695 6 жыл бұрын
Thanks a lot! very useful and well explained
@ancentropia3418
@ancentropia3418 3 жыл бұрын
Very good tutorial! Thanks a lot
@francescobucciol6381
@francescobucciol6381 5 жыл бұрын
Very nice tutorial! Thank you
@andsparky
@andsparky 6 жыл бұрын
Very helpful! Thanks!
@wak6880
@wak6880 5 жыл бұрын
i just went from hello world to TCP server
@radon1221
@radon1221 5 жыл бұрын
congrats
@Coranthh
@Coranthh 5 жыл бұрын
TCP server where you type hello world
@DeltaSigma16
@DeltaSigma16 4 жыл бұрын
Congrégations dude , you are genius :)
@BizzaroBrainBoi
@BizzaroBrainBoi 4 жыл бұрын
lol
@suhailahmed2310
@suhailahmed2310 3 жыл бұрын
Aye congratulations its a celebration!
@yuvaraj9268
@yuvaraj9268 4 жыл бұрын
nice illustration, thank you
@gaiabellovi7560
@gaiabellovi7560 5 жыл бұрын
Really useful and interesting!
@0x_Anakin
@0x_Anakin 5 жыл бұрын
best tutorial around!
2 жыл бұрын
Thaks, great intro. I learned it.
@talltreecustoms
@talltreecustoms 6 жыл бұрын
God this is so useful. Thank you so much!
@alexandrujugureanu3752
@alexandrujugureanu3752 2 жыл бұрын
you re top, for real, lot of thanks for those videos, help a lot at school, love you for this, saves a lot of time for me
@adriel8140
@adriel8140 4 жыл бұрын
It worked! Thank you!
@vishwanathpai16
@vishwanathpai16 3 жыл бұрын
Hi Sloan Kelly. Thanks for the tutorial you provided. I do have some questions though regarding the echo part. How does the client side interpret the bytes which are echoed to it? Is there an inbuilt function which readily converts the bytes of data to a string?
@sloankelly
@sloankelly 3 жыл бұрын
Sort of. On the client side you can create a std::string with a byte array.
@alexanderhulton2748
@alexanderhulton2748 4 жыл бұрын
I have a question, Sloan. Why didn't you use the addrinfo struct members, like ai_flag, or ai_protocall? And would you recommend the method I'm using?
@anlakkaya5511
@anlakkaya5511 5 жыл бұрын
thanks, this was helped me a lot last year, and allowed me to code a big program to achieve my dreams.
@ridwaanbham1779
@ridwaanbham1779 5 жыл бұрын
Thank you for simplifying Modbus TCP communication. The fact that you went through it step by step, illustrating the thought process really helps. Out of curiosity if one wanted to receive more than one value from the communication what would be the simplest way to do this?
@sloankelly
@sloankelly 5 жыл бұрын
Not sure what you mean by more than one value, but the socket is always listening and when recv() is called anything in the buffer will be read in.
@nguyenthaile2024
@nguyenthaile2024 Жыл бұрын
OMG!!!!! THANK YOU SIR, YOU SAVE my LIFE!!!!!!!!! GOD BLESS YOU!!!!!
@triphuong818
@triphuong818 5 жыл бұрын
thank you for a great tutorial :3
@bahnny
@bahnny 7 жыл бұрын
just wanted to say great video, I'm going to play with this a bit. I wanted to add th reason you had trouble with putty at the end is you connected using ssh and not telnet. completely different protocol :) cheers
@sloankelly
@sloankelly 7 жыл бұрын
I always forget to hit that setting. I also miss ;'s and assign fields in the inspector :)
@Metruzero
@Metruzero 3 жыл бұрын
Great resource, except for changing putty from ssh to raw, everything worked great! Thanks so much for the video.
@sloankelly
@sloankelly 3 жыл бұрын
Glad it helped!
@w.t.2905
@w.t.2905 3 жыл бұрын
Очень помог, спасибо огромное!
@LachyBalboa1
@LachyBalboa1 6 жыл бұрын
Hey Sloan Kelly or anyone else. Do you have any ideas about what we could do to make this program vulnerable and how might be exploited? E.g. modifying the buffer size?
@catalinstefanteodorescu2996
@catalinstefanteodorescu2996 6 жыл бұрын
Great! It compiled and worked on my VS2015. A question please: is this code indeed C++ (as mentioned in the title) or just C ?
@sloankelly
@sloankelly 6 жыл бұрын
+Stefan T. It is, in that it won't compile using a C compiler.
@catalinstefanteodorescu2996
@catalinstefanteodorescu2996 6 жыл бұрын
Thank you for your answer. Another question please. For one message sent from putty, I checked in debugging mode that the while-loop inside the server runs 2 iterations, instead of one as I would have expected. First iteration it receives the message part (ex. "Hello world!" but without '\0' at the end) and sends it back to putty; the second iteration it receives a 2-bytes message consisting in ' ' which is also sent back to putty. For this reason we get an extra blank line in putty between messages. Any understanding why this happens, and how to avoid the second iteration? Thank you.
@sloankelly
@sloankelly 6 жыл бұрын
AFAIK this is a putty issue. Shouldn't be an issue with other clients.
@0xb15h4l
@0xb15h4l 2 жыл бұрын
a nice approach to explain and it is methodological! Impressive!
@masterpc-9845x
@masterpc-9845x 6 жыл бұрын
Hi Sloan. I've only lived with a Linux VM Workstation for those socket programs. When I tried them on Windows, I have a few errors and thus can't compile them. Did I miss any important file or setting?
@sloankelly
@sloankelly 6 жыл бұрын
What errors did you get? And what compiler/IDE are you using?
@saikirangattu2924
@saikirangattu2924 6 жыл бұрын
Hi Sloan, best video ever on TCP IP. It worked for me when I built it couple months ago. Now it does not. I get an exception in server solution when I call "accept()" function. I have a feeling "sockaddr_in client;" object is not right. I tried using try catch but it does not handle the exception. //Wait for communication sockaddr_in client; int clientSize = sizeof(client); SOCKET clientSocket; try { sockaddr * p = (sockaddr*)&client; clientSocket = accept(listening_socket, (sockaddr*)&client, &clientSize);//*Exception here* } catch (...) { clientSocket = NULL;// just clearing ... clientSocket = accept(listening_socket, (sockaddr*)&client, &clientSize); } I also get an exception in "connect()" function in client. //Connect to server int ConnResult = 0; try { ConnResult = connect(sock, (sockaddr*)&hint, sizeof(hint)); } catch (...) { ConnResult = 0; ConnResult = connect(sock, (sockaddr*)&hint, sizeof(hint));// dont know what to do trying connect again }
@iamklevy
@iamklevy 2 жыл бұрын
thank you sir we appreciate that❤❤
@kevinbento770
@kevinbento770 4 жыл бұрын
Thank you!!
@sayna3
@sayna3 Жыл бұрын
Great resource
@adrianoldchannel2494
@adrianoldchannel2494 6 жыл бұрын
You are the boss.
@phudinhtruong
@phudinhtruong 3 жыл бұрын
Thank god it work
@justcode5626
@justcode5626 2 жыл бұрын
Danke schon!
@dennisschnapka9148
@dennisschnapka9148 4 жыл бұрын
It works, thank you :)
@cherifaly6757
@cherifaly6757 Жыл бұрын
Thank you for your amazing tutorial! I have one question please, what if I want to receive and send more than 4kb? What you recommend doing in this case?
@sloankelly
@sloankelly Жыл бұрын
Thanks :) You can prefix your message with a header that will have the size of the payload. The receiving program then reads the bytes received and loads in the header. The header is _usually but not always_ a fixed size. Assuming it is and it contains four bytes that represent the size of the payload. I've written a _terrible_ pseudo code, but hopefully it illustrates what I mean. gist.github.com/codehoose/9be1ffa71353e2ec83f1823225467a00
@dennisschnapka9148
@dennisschnapka9148 4 жыл бұрын
On line 86. I want to implement if I write e.g. 1 that the proagam startr google with the ShellExecuteA function. How can I put it in a If statement?
@mykhailomorhal2181
@mykhailomorhal2181 6 жыл бұрын
thanks )
@Kitiara306
@Kitiara306 2 жыл бұрын
Nice example
@rabit1998g
@rabit1998g 4 жыл бұрын
is there way to send data to the server not via the same computer where the server is running, but from another device?
@kezwikHD
@kezwikHD 6 жыл бұрын
do you have a tip to fix the Connection refuse error? i don't really find a webpage that helpps me out. i just downloaded putty maybe i have to setup something in putty? and my VS always gets the error that it cant open the Serer exe in the Debug file, but when i switch to release mode it is possible.
@kezwikHD
@kezwikHD 6 жыл бұрын
and now suddenly VS can't open it on Relese and Debug
@turke511
@turke511 4 жыл бұрын
Thank you You just save me
@dimitarvel1441
@dimitarvel1441 4 жыл бұрын
What kind of keyboard have you got? Sounds very good.
@sloankelly
@sloankelly 4 жыл бұрын
Razer Blackwidow Stealth. 2014 I think?
@emmanuelamodu1066
@emmanuelamodu1066 6 жыл бұрын
I would love to know how to do this for in linux specificly cent os
@jodumagpi
@jodumagpi 5 жыл бұрын
This is awesome but I wish the video quality is better
@marcovalentinoalvarado3290
@marcovalentinoalvarado3290 5 жыл бұрын
Sloan, im needing help, im trying to deal with this error: "Invalid padding length on received packet"
@sloankelly
@sloankelly 5 жыл бұрын
Are you using PUTtY? If so, make sure it’s set to “raw”.
@marcovalentinoalvarado3290
@marcovalentinoalvarado3290 5 жыл бұрын
Sloan Kelly Sir, I really appreciate your help, I gave you a Like and I'm already subscribed, you've done an excellent job with these tutorials, keep teaching, you're amazing :)
@sloankelly
@sloankelly 5 жыл бұрын
Thank you!
@mrcollie7210
@mrcollie7210 3 жыл бұрын
@@sloankelly I like your video very much, i recommended it to friends and give you a like!
@TheClonerx
@TheClonerx 6 жыл бұрын
using namespace std; void main() my god, you are crazy
@kebluetugirafee7558
@kebluetugirafee7558 6 жыл бұрын
why crazy?This very short code block never use another namespace which may cause confused with "std".emmm...whatever,you are right ,but that's not the key point for this video.
@janmerta8651
@janmerta8651 6 жыл бұрын
void?
@blackgarfieldyt
@blackgarfieldyt 5 жыл бұрын
The C++ standard requires main() to return int. Also, its bad convention to use "using namespace".
@NoSoupForYouu
@NoSoupForYouu 5 жыл бұрын
Why is it bad convention? genuinely asking. Why would I want to constantly state std:: every time?
@Spirrwell
@Spirrwell 5 жыл бұрын
For here I'd argue using namespace std; is not a bad convention. Where it can be bad is doing it in a header file. That would mean any file that includes that header would also use the namespace, and that might not be what you want. You could have functions, classes, etc. that have the same names and run into conflicts. For example, using min() and max(), they're in the std namespace, but you could have those same names elsewhere.
@gabrielstefan8037
@gabrielstefan8037 6 жыл бұрын
eroare la compliare , ii lipseste entry point :D
@brocksprogramming
@brocksprogramming 6 жыл бұрын
I know you used Visual Studio for this. Is there any way to do this using a free compiler like codeblocks? The problem I ran into is that the pragma isn't implemented. The only two errors are with getnameinfo() and inet_ntop. I'm guessing that they're found inside of the pragma library included.
@israjacome6771
@israjacome6771 6 жыл бұрын
excellent explanation, please can you help me instead of sending the customer a greeting or string, I need to send vectors with integer values ​​as I do that?
@sloankelly
@sloankelly 6 жыл бұрын
I'm AFK at the moment, but it'd be something like this: struct MyStruct { int x; int y; int z; } MyStruct s; // initialize struct with values char* ptr2Struct = (char*)&s; int sent = send(socket, ptr2Struct, sizeof(MyStruct), 0); On the receiving end: int read = recv(socket, buf, bufsize, 0); MyStruct* s = (MyStruct*)buf; You'd do something similar for other value types like int, float etc.
@wojciechbroka5989
@wojciechbroka5989 4 жыл бұрын
Sloan your application is great! How can I change the mode from blocking to non-blocking socket?
@sloankelly
@sloankelly 4 жыл бұрын
Thanks :) check out the ioctlsocket function docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-ioctlsocket
@davidmwangi281
@davidmwangi281 4 жыл бұрын
nice one
@cangorkemgunes
@cangorkemgunes Жыл бұрын
Hi sir, i just wanted to ask you some questions. Firstly, i have a microcontroller which is client for a socket server. Now, i would like to develop a socket server and want to deploy it my domain/hosting. How can i write it, do you have knowledge about it. I mean if i just write and example server like your codes does it work on a domain. What should i do?(My hosting is a windows server)
@megasalexander579
@megasalexander579 4 жыл бұрын
If I transfer the compiled program to another PC, when I run it I get an error saying me that vcruntime140d.dll is missing. How can I do? (I'd prefer not to have to install Visual C++ or other stuff on that PC). Thanks
@sloankelly
@sloankelly 4 жыл бұрын
Make a release build of your application and copy it to the other machine. The dll that is missing is the debug runtime. The C++ runtime is probably on the target pc. If not, you will need to install that. I think this is the right version for vs2015? www.microsoft.com/en-us/download/details.aspx?id=52685
@haveityourwa1
@haveityourwa1 5 жыл бұрын
Hey thanks for the guide, you linked to the client not the server files, easy enough to find though Cheers
@awaixchodry
@awaixchodry 4 жыл бұрын
hello sir.. can you please tell me how to implement linked list code to server .. socket programming?
@TeddieMovie
@TeddieMovie 7 жыл бұрын
Hello Sloan, i tried your code but i get an error from Putty saying: " Invalid padding length on recieced packet". Im farely new to C++ so i dont really know how to resolve this issue. your explanation was very good though :)
@sloankelly
@sloankelly 7 жыл бұрын
Thanks :) Did you set PuTTY to 'Raw' ?
@TeddieMovie
@TeddieMovie 7 жыл бұрын
with your "custom" tcp client everything worked so i think it is fixed.
@TeddieMovie
@TeddieMovie 7 жыл бұрын
Yeah tried that aswell but didnt work either.
@joachimkaddah6040
@joachimkaddah6040 7 жыл бұрын
I had the same error and I did same as Mr.Kellz said and it work it.
@kezwikHD
@kezwikHD 6 жыл бұрын
which custom tcp client?
@usama57926
@usama57926 6 жыл бұрын
can you help me in a problem that how to add graphics in visual studio
@ThaiPham-bm9si
@ThaiPham-bm9si 4 жыл бұрын
hello. i have problem! when i click Local Windows Debugger, it start 2s then close.thanks
@virozz1024
@virozz1024 3 жыл бұрын
are u kidding men ?
@ramasif9983
@ramasif9983 6 жыл бұрын
I am new to coding and am trying to establish a TCP written in C++ for linux - I was wondering if this tutorial can be used there too? Saw some other tutorials for linux, where they do not use e.g. WSA-libraries? Thanks
@sloankelly
@sloankelly 6 жыл бұрын
WS is WinSock which is short for Windows Sockets Layer, which you won't have available to you because you're using Linux. You will need to include the correct headers for Linux and ignore any WSA....() functions.
@ramasif9983
@ramasif9983 6 жыл бұрын
Thank you very much for the answer. And for the video of course.
@brendanlydon5272
@brendanlydon5272 3 жыл бұрын
Does it matter what port number you input into the htons() around 11:40? He does not specify where this value comes from and I am wondering if it is arbitrary. Spent many hours before trying to build a server using ASIO and I think the port number matter? With ASIO I tried using port numbers attached to my local ip address through the command prompt and it did not seem to run implement or connect to the server. I probably did something wrong, but hey. Thanks in advanced
@sloankelly
@sloankelly 3 жыл бұрын
It’s doesn’t matter so long as the client connects to that port number. I’d recommend using a port number between 1024 and 65535 that isn’t used by your local machine (the server)
@rednassie1101
@rednassie1101 4 жыл бұрын
Well this is quite the step-up from Python.. :P
@sirgouki6207
@sirgouki6207 4 жыл бұрын
My version has an interesting problem that I can not pin down: If I send the message back to the client, it adds another line end (can't tell why because I can't figure out how to print the exact byte contents of the buffer). I can send any cstring to the client (const char *... like "Test") and it gets the exact message without adding an extra line end. I typed the code while following the video, and aside from a function I'm using as a shortcut to std::cout
@BluecoreG
@BluecoreG 4 жыл бұрын
Avast and all anti virus programs are scams! Nothing beats Windows Defender and smart internet browsing. Great tutorial by the way!!
@sirgouki6207
@sirgouki6207 4 жыл бұрын
Windows Defender *is* an antivirus... Those other programs existed before Windows Defender, and it borrows a lot from them.
@sonaion5668
@sonaion5668 5 жыл бұрын
first of all thank you. but how can i connect 2 different devices via the internet using tcp/ip server, i got it by using hamachi to get 2 devices to the same network, but how can i do it without?
@csteam7287
@csteam7287 5 жыл бұрын
You can open a port on your rooter and use that port in your program and then use your rooter's public ip
@colepeterson5392
@colepeterson5392 6 жыл бұрын
I dont get any errors, but typing into putty results in multiple characters being pushed for instance 'a' types as 'aaaa'. Pressing enter does not echo the message back either. I thought maybe its constantly echoing without ending line but I followed the code exactly. Any ideas? Also, Awesome video.
@colepeterson5392
@colepeterson5392 6 жыл бұрын
Nevermind! If anyone has this problem, I set the connection type to Raw and it worked!
@sloankelly
@sloankelly 6 жыл бұрын
+Cole Peterson thanks! Is putty in raw mode? If not, try that.
@sloankelly
@sloankelly 6 жыл бұрын
+Cole Peterson thanks for posting the solution!
@ochenhoroshy6104
@ochenhoroshy6104 5 жыл бұрын
I am new to C++. Does this tutorial fit for Unix users?
@jflopezfernandez
@jflopezfernandez 5 жыл бұрын
*nix systems use actual Berkley socket implementation code, which is slightly different. The Windows version is really similar but there are some differences that would cause compiler errors, such as the WSA prefix. WinSock, specifically WinSock2, which is the version of WinSock in modern systems, is a port of the original Berkeley sockets for Windows. So this exact code won't run on *nix systems, but the correct code is very similar and you should be able to find it either online or through books like Unix network programming. If you're on a Unix-like system, anything by Richard Stevens is worth its weight in both gold and silver
@amrtcpp6203
@amrtcpp6203 3 жыл бұрын
Big Like, keep on please
@sloankelly
@sloankelly 3 жыл бұрын
Thank you, I will :)
@ucluu7281
@ucluu7281 5 жыл бұрын
Great video .How to transfer many file between server and client ? Thank you so much ?
@sloankelly
@sloankelly 5 жыл бұрын
I'm just about to upload a web server video and that will cover most of what you're looking for.
@LusidDreaming
@LusidDreaming 4 жыл бұрын
Why is clientSize a pointer? Is it possibly modified in any way when the connection is accepted?
@sloankelly
@sloankelly 4 жыл бұрын
It can be, yes. It depends on the size of the sockaddr struct that is returned by the function.
@geckoo9190
@geckoo9190 5 жыл бұрын
Ho men i have being trying to make a socket program work like for three days, its a real problem with the libraries, that you have to use this or that you have to use that, at the end all those libraries are full of holes.
@jwk7317
@jwk7317 3 жыл бұрын
sorry im korean so im not used to be using english i just start socket programming so am i create two project server project and client project?
@sloankelly
@sloankelly 3 жыл бұрын
You can use PuTTY to connect to the server, or if you want you can use this one: kzbin.info/www/bejne/ZovVkGOArp2gjac
@jwk7317
@jwk7317 3 жыл бұрын
@@sloankelly thank you so much
@harkibains8787
@harkibains8787 4 жыл бұрын
Great video, but I ran into the following problem. SOCKET clientSocket = accept(listening, (sockaddr*)&client, &clientSize); Immediately returns INVALID_SOCKET . From what I've read accept() should wait for a client connection and then return. Running without modification results in; 204.204.204.204 connected to port 52428 Error in recv(). Quitting I have tried changing the port number and "sockaddr_in client = {};" Any suggestions would help.
@NiceBot724
@NiceBot724 6 жыл бұрын
I wrote the exact same code in VS2017 but once i hit "local windows debugger" a prompt flashes and goes away.. when i tried to run the "bearboneserver.exe" file in my debug folder through the command prompt i get "cannot start winsock" message. I don't know where i am going wrong. Please help me out
@sloankelly
@sloankelly 6 жыл бұрын
+Gourish Biradar write out the error code returned from WSAStartup() and look the value up here: msdn.microsoft.com/en-us/library/windows/desktop/ms742213(v=vs.85).aspx
@LaGordita732
@LaGordita732 2 жыл бұрын
Hello, I have encountered problem with ntons, as the compiler says there is an error with that (supposedly, it's not defined)
@sloankelly
@sloankelly 2 жыл бұрын
What IDE / compiler are you using?
@sloankelly
@sloankelly 2 жыл бұрын
If you’re trying to get Winsock to work with anything other than Visual Studio, this video might help. kzbin.info/www/bejne/bKKnZH-PfZKMpK8
@sloankelly
@sloankelly 2 жыл бұрын
It's htons too btw.
@58gullu58
@58gullu58 5 жыл бұрын
We get an bad request header error how can we fix that?
@ChungusTheLarge
@ChungusTheLarge 4 жыл бұрын
Okay I'm curious. Why did you do your design in comments instead of a pure virtual class, or both?
@sloankelly
@sloankelly 4 жыл бұрын
I wanted to concentrate on just barebones networking without adding complexity. It’s a tough subject to get into if you’re just starting, so barebones was the way I wanted to go. The comments were something I’ve done before. It “keeps me honest” in that it is easy to see what steps to code and in what order the operations should be performed.
@user-dz4qq7gv1w
@user-dz4qq7gv1w 7 жыл бұрын
how to send file or chat in between computer in ftp ?
@B1TCH35K1LL3R
@B1TCH35K1LL3R 6 жыл бұрын
why does it need the pragma declaration on the main.cpp file?
@sloankelly
@sloankelly 6 жыл бұрын
To include the Winsock library. The alternative is to go into project settings and add it there.
@shashipreethampreetham316r
@shashipreethampreetham316r 3 жыл бұрын
I am getting an error of "invalid padding length on received packets" in putty while opening the client with 127.0.0.1 and 54000
@sloankelly
@sloankelly 3 жыл бұрын
Set Putty to use RAW instead of SSH.
Creating a TCP Server in C++ [Linux / Code Blocks]
43:15
Sloan Kelly
Рет қаралды 84 М.
Starter UDP Server And Client in C++
35:51
Sloan Kelly
Рет қаралды 82 М.
Они убрались очень быстро!
00:40
Аришнев
Рет қаралды 3,5 МЛН
TRY NOT TO LAUGH 😂
00:56
Feinxy
Рет қаралды 20 МЛН
La revancha 😱
00:55
Juan De Dios Pantoja 2
Рет қаралды 70 МЛН
Homemade Professional Spy Trick To Unlock A Phone 🔍
00:55
Crafty Champions
Рет қаралды 55 МЛН
coding in C but I start over for every compiler error
16:34
Low Level Learning
Рет қаралды 263 М.
Socket Server Class in C++ - Abstracting the Network Layer
41:45
Sloan Kelly
Рет қаралды 22 М.
Transport Layer Security (TLS) - Computerphile
15:33
Computerphile
Рет қаралды 469 М.
Object-Oriented Programming is Bad
44:35
Brian Will
Рет қаралды 2,3 МЛН
Networking in C++
32:50
The Cherno
Рет қаралды 230 М.
C++ Network Programming Part 1: Sockets
1:13:52
Nicholas Day
Рет қаралды 105 М.
Multiple Chat Clients: One Thread (in C++)
27:46
Sloan Kelly
Рет қаралды 133 М.
Они убрались очень быстро!
00:40
Аришнев
Рет қаралды 3,5 МЛН