Creating a TCP Server in C++

  Рет қаралды 325,970

Sloan Kelly

Sloan Kelly

Күн бұрын

#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.gree...
Full source can be downloaded here: bitbucket.org/...

Пікірлер: 548
@RaZziaN1
@RaZziaN1 5 жыл бұрын
For people with error "invalid padding length" instead of using SSH in puty, use RAW.
@Gavy093
@Gavy093 5 жыл бұрын
If I may ask ...How did u figure that out?
@sirgouki6207
@sirgouki6207 5 жыл бұрын
@@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!!
@gangelo777
@gangelo777 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 6 ай бұрын
7 year old video and still one of the best resources on this topic I could find. Amazing.
@sloankelly
@sloankelly 6 ай бұрын
Glad it was helpful!
@heavymetalmixer91
@heavymetalmixer91 3 ай бұрын
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 3 ай бұрын
@@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.
@agentk3984
@agentk3984 5 жыл бұрын
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 3 жыл бұрын
@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?
@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
@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.
@stevenhine8269
@stevenhine8269 4 жыл бұрын
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 4 жыл бұрын
You might get away with just changing the port number to something else. Another service might be using 54000.
@wamxfl1p653
@wamxfl1p653 6 жыл бұрын
"I won't cover any error handling from now on. This program won't fail. I think." Lmfaooo
@wak6880
@wak6880 6 жыл бұрын
i just went from hello world to TCP server
@radon1221
@radon1221 6 жыл бұрын
congrats
@Coranthh
@Coranthh 6 жыл бұрын
TCP server where you type hello world
@DeltaSigma16
@DeltaSigma16 5 жыл бұрын
Congrégations dude , you are genius :)
@BizzaroBrainBoi
@BizzaroBrainBoi 4 жыл бұрын
lol
@suhailahmed2310
@suhailahmed2310 4 жыл бұрын
Aye congratulations its a celebration!
@jackbailey049
@jackbailey049 3 жыл бұрын
The amounts of stuff you can learn through youtube! Thank you
@delysid604
@delysid604 2 жыл бұрын
Thank you mate. Clear explanation all ur steps. Good vid
@garyrogers378
@garyrogers378 5 жыл бұрын
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!!!
@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.
@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//
@brocksprogramming
@brocksprogramming 7 жыл бұрын
I got it working, great video sir.
@emperorj4783
@emperorj4783 3 жыл бұрын
Thank you. This really helped me! You are the only one with a good tutorial
@dinoconsabor
@dinoconsabor 3 жыл бұрын
This was a great introduction to sockets programming for me.
@TheTheThewillow
@TheTheThewillow 3 жыл бұрын
I would recommend checking a video in C and not C++. This is just not detailed and more object oriented
@dinoconsabor
@dinoconsabor 3 жыл бұрын
@@TheTheThewillow at the time they were looking into C++, but I agree.
@TheClonerx
@TheClonerx 7 жыл бұрын
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 6 жыл бұрын
The C++ standard requires main() to return int. Also, its bad convention to use "using namespace".
@NoSoupForYouu
@NoSoupForYouu 6 жыл бұрын
Why is it bad convention? genuinely asking. Why would I want to constantly state std:: every time?
@Spirrwell
@Spirrwell 6 жыл бұрын
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.
@phudinhtruong
@phudinhtruong 4 жыл бұрын
Thank god it work
@nguyenthaile2024
@nguyenthaile2024 2 жыл бұрын
OMG!!!!! THANK YOU SIR, YOU SAVE my LIFE!!!!!!!!! GOD BLESS YOU!!!!!
@omarl7333
@omarl7333 7 жыл бұрын
i using the raw option in putty, work perfect! ty great tutorial
@dheerajsharma5492
@dheerajsharma5492 5 жыл бұрын
thanks for neat and clean explanation
@kulaningobeni20
@kulaningobeni20 4 жыл бұрын
Thanks for the time and effort put in this video. It is very informative.
@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 :)
@ridwaanbham1779
@ridwaanbham1779 6 жыл бұрын
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 6 жыл бұрын
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.
@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
@TheVestinius
@TheVestinius 6 жыл бұрын
God this is so useful. Thank you so much!
2 жыл бұрын
Thaks, great intro. I learned it.
@adriel8140
@adriel8140 4 жыл бұрын
It worked! Thank you!
@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 }
@0xb15h4l
@0xb15h4l 3 жыл бұрын
a nice approach to explain and it is methodological! Impressive!
@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?
@usama57926
@usama57926 6 жыл бұрын
Hi Sloan Kelly, your explanation is nice
@francescobucciol6381
@francescobucciol6381 5 жыл бұрын
Very nice tutorial! Thank you
@0x_Anakin
@0x_Anakin 5 жыл бұрын
best tutorial around!
@yuvaraj9268
@yuvaraj9268 4 жыл бұрын
nice illustration, thank you
@gaiabellovi7560
@gaiabellovi7560 5 жыл бұрын
Really useful and interesting!
@swiftsifu
@swiftsifu 6 жыл бұрын
Great tutorial, thank you.
@Metruzero
@Metruzero 4 жыл бұрын
Great resource, except for changing putty from ssh to raw, everything worked great! Thanks so much for the video.
@sloankelly
@sloankelly 4 жыл бұрын
Glad it helped!
@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.
@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.
@andsparky
@andsparky 6 жыл бұрын
Very helpful! Thanks!
@sirgouki6207
@sirgouki6207 5 жыл бұрын
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
@cangorkemgunes
@cangorkemgunes 2 жыл бұрын
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)
@anlakkaya5511
@anlakkaya5511 5 жыл бұрын
thanks, this was helped me a lot last year, and allowed me to code a big program to achieve my dreams.
@giuseppe1695
@giuseppe1695 6 жыл бұрын
Thanks a lot! very useful and well explained
@jared0801
@jared0801 3 жыл бұрын
If you're using a different ide (Im using vscode) and you're getting an error about "inet_ntop was not declared" you may need to define _WIN32_WINNT so the compiler knows what system you're compiling for. I'm on windows 10 so adding "#define _WIN32_WINNT _WIN32_WINNT_WIN10" above all my code fixed the problem for me. More info here: docs.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers?redirectedfrom=MSDN#setting-winver-or-_win32_winnt If using gcc you may also need the flag "g++ server.c -o server -lws2_32"
@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.
@manual720
@manual720 6 жыл бұрын
Set to Raw and it worked, 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
@BluecoreG
@BluecoreG 5 жыл бұрын
Avast and all anti virus programs are scams! Nothing beats Windows Defender and smart internet browsing. Great tutorial by the way!!
@sirgouki6207
@sirgouki6207 5 жыл бұрын
Windows Defender *is* an antivirus... Those other programs existed before Windows Defender, and it borrows a lot from them.
@dimitarvel1441
@dimitarvel1441 4 жыл бұрын
What kind of keyboard have you got? Sounds very good.
@sloankelly
@sloankelly 4 жыл бұрын
Razer Blackwidow Stealth. 2014 I think?
@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?
@sayna3
@sayna3 Жыл бұрын
Great resource
@iamklevy
@iamklevy 2 жыл бұрын
thank you sir we appreciate that❤❤
@rabit1998g
@rabit1998g 5 жыл бұрын
is there way to send data to the server not via the same computer where the server is running, but from another device?
@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?
@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
@ThaiPham-bm9si
@ThaiPham-bm9si 4 жыл бұрын
hello. i have problem! when i click Local Windows Debugger, it start 2s then close.thanks
@virozz1024
@virozz1024 4 жыл бұрын
are u kidding men ?
@justcode5626
@justcode5626 3 жыл бұрын
Danke schon!
@vishwanathpai16
@vishwanathpai16 4 жыл бұрын
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 4 жыл бұрын
Sort of. On the client side you can create a std::string with a byte array.
@matruprasadgantayat5160
@matruprasadgantayat5160 2 жыл бұрын
Hey man, it shows cannot opensource file"sys/socket.h" ,same with "netinet/in h>.Any idea why is it happening?
@sloankelly
@sloankelly 2 жыл бұрын
What dev environment are you using? What IDE and compiler? My guess is that it’s not VS Studio/msbuild?
@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?
@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.
@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.
@awaismushtaq5719
@awaismushtaq5719 2 жыл бұрын
Excuse me Mr. Kelly, you must also switch theme from dark to light for better viewing because in this theme every thing looks dark so so dark and puts strain on viewers' eyes!
@sloankelly
@sloankelly 2 жыл бұрын
An epic debate to be sure. What do other people think? Do you use dark or light mode? Which one would you prefer for these videos?
@awaismushtaq5719
@awaismushtaq5719 2 жыл бұрын
@@sloankelly I would say light theme. Black text against white background puts less strain on eyes and is ergonomically compliant. Choice is yours however!
@sloankelly
@sloankelly 2 жыл бұрын
I created a poll in the channel. It’s an interesting question.
@dennisschnapka9148
@dennisschnapka9148 4 жыл бұрын
It works, thank you :)
@awaixchodry
@awaixchodry 4 жыл бұрын
hello sir.. can you please tell me how to implement linked list code to server .. socket programming?
@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)
@Buruhtania
@Buruhtania 2 жыл бұрын
26:35 How to properly detect the client was disconnected without any errors? It's always returns the SOCKET_ERROR code after closing the client socket.
@sloankelly
@sloankelly 2 жыл бұрын
That's what happens when a client disconnects. Check the recv() result, if it's < 1 then the client pulled the plug.
@Buruhtania
@Buruhtania 2 жыл бұрын
@@sloankelly No, i mean how to detect disconnection reason? The client was disconnected by itself or the connection was unexpectedly interrupted.
@sloankelly
@sloankelly 2 жыл бұрын
That’s not possible and I’m not sure it matters anyway? The connection dropped and that’s enough of a signal to let the program know to clean up anything that uses it.
@Buruhtania
@Buruhtania 2 жыл бұрын
@@sloankelly Ok, i understand. Thanx. I liked this video. I understand socket principal. I think you need to write a simple client-server game. Something like pong.
@dennisschnapka9148
@dennisschnapka9148 4 жыл бұрын
now it is compiling but he cannot find ... .obj, what I should do?
@chimpionboy
@chimpionboy 6 жыл бұрын
You are the boss.
@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
@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.
@w.t.2905
@w.t.2905 3 жыл бұрын
Очень помог, спасибо огромное!
@alexmao8805
@alexmao8805 3 жыл бұрын
I always receive 204.204.204.204, which seems error in recv() function. The first time I try, it was successful, but now it always shows I have connected in 204.204.204.204.what can I do?
@alexmao8805
@alexmao8805 3 жыл бұрын
this is my error:"204.204.204.204connected on port52428"
@alexmao8805
@alexmao8805 3 жыл бұрын
I changed my port from 54000 to 54001, It worked, but why? it seems port 54000 can't be used.
@alexmao8805
@alexmao8805 3 жыл бұрын
I fixed it by release port 54000, the port is disabled. Thank you for the tutorial!
@thecolgatemann
@thecolgatemann 2 жыл бұрын
Is it possible to make it work on WAN? like i could make a messaging app out of it?
@sloankelly
@sloankelly 2 жыл бұрын
Absolutely. Use IP ANY or 0.0.0.0 for the address. Any computer on your LAN will then be able to communicate with the server. For WAN it’s a bit more complex because you’ll probably need a static IP or other network configuration to get it to work on the net. Way beyond my expertise though. And it would depend on your Internet provider and other networking considerations
@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.
@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!
@ubiquitous9173
@ubiquitous9173 4 жыл бұрын
'inet_ntop' was not declared in this scope? How do I fix that? I am using Code::Blocks MinGW64 Windows 7.
@sloankelly
@sloankelly 4 жыл бұрын
This video will help you! I was asked before about how to get this to work with CodeBlocks kzbin.info/www/bejne/bKKnZH-PfZKMpK8
@ubiquitous9173
@ubiquitous9173 4 жыл бұрын
@@sloankelly Oh ok thanks!
@triphuong818
@triphuong818 5 жыл бұрын
thank you for a great tutorial :3
@Auron380
@Auron380 4 жыл бұрын
I am getting errors: getnameinfo and inet_ntop is undefined?? Why is this? I am importing ws2tcpip.h. Is it because they are obsolete now?
@sloankelly
@sloankelly 4 жыл бұрын
What IDE are you using on what platform?
@Auron380
@Auron380 4 жыл бұрын
@@sloankelly I was using visual studio code with mingw. I think it had something to do with the library that was included in the package, I migrated everything over to visual studio community and the problem disappeared. I now have a problem with connecting to localhost on putty, but I think that is some native to Windows or my firewall.. if you have some tips about this, let me know! I am using your tutorial for an upcoming interview assignment, and it is very useful! Thanks for replying!
@sloankelly
@sloankelly 4 жыл бұрын
If you’re using mingw it will require some extra steps. I did this video for CodeBlocks, it might work for mingw too. kzbin.info/www/bejne/bKKnZH-PfZKMpK8
@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
@geckoo9190
@geckoo9190 6 жыл бұрын
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.
@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.
@emmanuelamodu1066
@emmanuelamodu1066 6 жыл бұрын
I would love to know how to do this for in linux specificly cent os
@ochenhoroshy6104
@ochenhoroshy6104 6 жыл бұрын
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
@garimamishra8934
@garimamishra8934 3 жыл бұрын
Hello sir, I have tried this code. And through putty when I am connecting local host afterthat I am not able to type something in putty What I can do for it ?
@sloankelly
@sloankelly 3 жыл бұрын
Is Putty in raw mode?
@shashipreethampreetham316r
@shashipreethampreetham316r 4 жыл бұрын
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 4 жыл бұрын
Set Putty to use RAW instead of SSH.
@Kitiara306
@Kitiara306 2 жыл бұрын
Nice example
@moazzamali3025
@moazzamali3025 4 жыл бұрын
Putty thing is not working on my windows 10 pro :(
@sloankelly
@sloankelly 4 жыл бұрын
Did you set it to “raw”?
@JawedCS
@JawedCS 6 жыл бұрын
hi, great tutorial ! However, I can't get it working :/ Im working with QT + MinGW and I'm getting this error 'inet_ntop was not declared in this scope'. Anyone had the same problem ?
@sloankelly
@sloankelly 6 жыл бұрын
Have I got a video for you!!! This Thursday ;)
@neethurenjith5557
@neethurenjith5557 4 жыл бұрын
Did you manage to fix it? Ran into the same error
@patrickFREE.
@patrickFREE. 3 жыл бұрын
@@neethurenjith5557 have you fix it ?
@turke511
@turke511 5 жыл бұрын
Thank you You just save me
@SgtP4in
@SgtP4in 5 жыл бұрын
If you go into the core shields section of Avast and set File Shield to off, it wont popup during compilation.
@sloankelly
@sloankelly 5 жыл бұрын
Thanks. I “fixed” it by removing avast and using a different antivirus.
@usama57926
@usama57926 6 жыл бұрын
can you help me in a problem that how to add graphics in visual studio
@colepeterson5392
@colepeterson5392 7 жыл бұрын
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 7 жыл бұрын
Nevermind! If anyone has this problem, I set the connection type to Raw and it worked!
@sloankelly
@sloankelly 7 жыл бұрын
+Cole Peterson thanks! Is putty in raw mode? If not, try that.
@sloankelly
@sloankelly 7 жыл бұрын
+Cole Peterson thanks for posting the solution!
@amrtcpp6203
@amrtcpp6203 4 жыл бұрын
Big Like, keep on please
@sloankelly
@sloankelly 4 жыл бұрын
Thank you, I will :)
@kennethhudgins1369
@kennethhudgins1369 7 жыл бұрын
Towards the end when you connect with your local 54000 I get an error...I obviously don't have that but I don't know how to movie forward.
@sloankelly
@sloankelly 7 жыл бұрын
Try another port #, like 54010. Make sure the client uses the same port. What's the error ..?
@moazzamali3025
@moazzamali3025 4 жыл бұрын
@@sloankelly, "Putty Fatal Error: Network Error, Connection Refused"
@dennisschnapka9148
@dennisschnapka9148 4 жыл бұрын
what is potty? 0:11
@sloankelly
@sloankelly 4 жыл бұрын
Putty is a telnet and ssh client.
@gabrielstefan8037
@gabrielstefan8037 6 жыл бұрын
eroare la compliare , ii lipseste entry point :D
Creating a TCP Client in C++
22:11
Sloan Kelly
Рет қаралды 84 М.
Creating a TCP Server in C++ [Linux / Code Blocks]
43:15
Sloan Kelly
Рет қаралды 87 М.
iPhone or Chocolate??
00:16
Hungry FAM
Рет қаралды 34 МЛН
when you have plan B 😂
00:11
Andrey Grechka
Рет қаралды 65 МЛН
АЗАРТНИК 4 |СЕЗОН 2 Серия
31:45
Inter Production
Рет қаралды 1,1 МЛН
C++ Network Programming Part 1: Sockets
1:13:52
Nicholas Day
Рет қаралды 123 М.
Minecraft Clone in C++ // Code Review
40:29
The Cherno
Рет қаралды 341 М.
Multiple Chat Clients: One Thread (in C++)
27:46
Sloan Kelly
Рет қаралды 134 М.
Emulating a CPU in C++ (6502)
52:28
Dave Poo
Рет қаралды 983 М.
Starter UDP Server And Client in C++
35:51
Sloan Kelly
Рет қаралды 84 М.
Kubernetes Course - Full Beginners Tutorial (Containerize Your Apps!)
2:58:01
Cross Platform Graphical User Interfaces in C++
44:49
javidx9
Рет қаралды 868 М.
iPhone or Chocolate??
00:16
Hungry FAM
Рет қаралды 34 МЛН