[{"data":1,"prerenderedAt":342},["ShallowReactive",2],{"blog-tcp_udp":3},{"id":4,"title":5,"body":6,"date":327,"description":328,"draft":329,"extension":330,"image":331,"meta":332,"navigation":333,"path":334,"seo":335,"stem":336,"tags":337,"__hash__":341},"blogs\u002Fblogs\u002Ftcp_udp\u002Findex.md","Understanding TCP and UDP: Key Networking Protocols",{"type":7,"value":8,"toc":319},"minimark",[9,13,18,21,34,38,41,52,56,66,79,87,124,128,135,140,147,160,173,189,208,212,228,240,247,251,282,292,296,299,315],[10,11,12],"p",{},"When it comes to network communication, two key protocols come into play: TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). Both serve different purposes, and understanding their differences is crucial for building efficient communication systems.",[14,15,17],"h3",{"id":16},"tcp-reliable-connection-oriented-communication","TCP: Reliable, Connection-Oriented Communication",[10,19,20],{},"TCP is all about reliability. It establishes a connection between client and server, ensuring every packet of data arrives safely and in order. This makes it ideal for use cases like:",[22,23,24,28,31],"ul",{},[25,26,27],"li",{},"Web Browsing: Ensures data (like HTML, CSS, images) is loaded correctly.",[25,29,30],{},"File Transfers: Guarantees the complete and accurate delivery of files.",[25,32,33],{},"Emails: Makes sure all parts of the email reach the recipient.",[14,35,37],{"id":36},"udp-fast-connection-less-communication","UDP: Fast, Connection-Less Communication",[10,39,40],{},"UDP, on the other hand, is all about speed. It sends data without establishing a connection, making it faster but less reliable than TCP. This is perfect for scenarios where real-time data is more important than complete accuracy:",[22,42,43,46,49],{},[25,44,45],{},"Video Streaming: Minimal delay is critical, even if some data is lost.",[25,47,48],{},"Online Gaming: Quick updates matter more than occasional packet loss.",[25,50,51],{},"Voice-over-IP (VoIP): Prioritizes continuous voice flow over packet delivery accuracy.",[14,53,55],{"id":54},"project-setup","Project setup",[57,58,59],"ol",{},[25,60,61,65],{},[62,63,64],"strong",{},"Requirements",":",[22,67,68],{},[25,69,70,71,78],{},"Install ",[72,73,77],"a",{"href":74,"rel":75},"https:\u002F\u002Fnodejs.org\u002F",[76],"nofollow","Node.js"," (v20.17.0 recommended).",[57,80,82],{"start":81},2,[25,83,84,65],{},[62,85,86],{},"Clone the Project",[88,89,94],"pre",{"className":90,"code":91,"language":92,"meta":93,"style":93},"language-bash shiki shiki-themes github-light","git clone https:\u002F\u002Fgithub.com\u002F9ovindyadav\u002Fl4_servers.git && cd l4_servers\n","bash","",[95,96,97],"code",{"__ignoreMap":93},[98,99,102,106,110,113,117,121],"span",{"class":100,"line":101},"line",1,[98,103,105],{"class":104},"s7eDp","git",[98,107,109],{"class":108},"sYBdl"," clone",[98,111,112],{"class":108}," https:\u002F\u002Fgithub.com\u002F9ovindyadav\u002Fl4_servers.git",[98,114,116],{"class":115},"sgsFI"," && ",[98,118,120],{"class":119},"sYu0t","cd",[98,122,123],{"class":108}," l4_servers\n",[14,125,127],{"id":126},"tcp-server","TCP Server",[57,129,130],{},[25,131,132],{},[62,133,134],{},"About",[22,136,137],{},[25,138,139],{},"This is a connection-oriented server, ensuring reliable communication between the client and server.",[57,141,142],{"start":81},[25,143,144],{},[62,145,146],{},"Run the TCP Server:",[88,148,150],{"className":90,"code":149,"language":92,"meta":93,"style":93},"node tcp_server.js\n",[95,151,152],{"__ignoreMap":93},[98,153,154,157],{"class":100,"line":101},[98,155,156],{"class":104},"node",[98,158,159],{"class":108}," tcp_server.js\n",[57,161,163],{"start":162},3,[25,164,165,168],{},[62,166,167],{},"Connect to the TCP Server:",[22,169,170],{},[25,171,172],{},"From another terminal or system, use:",[88,174,176],{"className":90,"code":175,"language":92,"meta":93,"style":93},"telnet localhost 8000\n",[95,177,178],{"__ignoreMap":93},[98,179,180,183,186],{"class":100,"line":101},[98,181,182],{"class":104},"telnet",[98,184,185],{"class":108}," localhost",[98,187,188],{"class":119}," 8000\n",[22,190,191,202],{},[25,192,193,194],{},"After the connection is established:\n",[22,195,196,199],{},[25,197,198],{},"Write a message in the terminal.",[25,200,201],{},"The message will be displayed in the server terminal.",[25,203,204,207],{},[62,205,206],{},"Note:","  If the server crashes, the connection will be lost.",[14,209,211],{"id":210},"udp-server","UDP Server",[57,213,214,223],{},[25,215,216,218],{},[62,217,134],{},[22,219,220],{},[25,221,222],{},"This is a connection-less server, offering fast, but potentially unreliable communication.",[25,224,225],{},[62,226,227],{},"Run the UDP Server:",[88,229,231],{"className":90,"code":230,"language":92,"meta":93,"style":93},"node udp_server.js\n",[95,232,233],{"__ignoreMap":93},[98,234,235,237],{"class":100,"line":101},[98,236,156],{"class":104},[98,238,239],{"class":108}," udp_server.js\n",[57,241,242],{"start":162},[25,243,244],{},[62,245,246],{},"Connect to the UDP Server:",[22,248,249],{},[25,250,172],{},[88,252,254],{"className":90,"code":253,"language":92,"meta":93,"style":93},"echo \"Hii\" | nc -w1 -u localhost 8001\n",[95,255,256],{"__ignoreMap":93},[98,257,258,261,264,268,271,274,277,279],{"class":100,"line":101},[98,259,260],{"class":119},"echo",[98,262,263],{"class":108}," \"Hii\"",[98,265,267],{"class":266},"sD7c4"," |",[98,269,270],{"class":104}," nc",[98,272,273],{"class":119}," -w1",[98,275,276],{"class":119}," -u",[98,278,185],{"class":108},[98,280,281],{"class":119}," 8001\n",[22,283,284],{},[25,285,286,287],{},"After sending a message:\n",[22,288,289],{},[25,290,291],{},"The message will appear in the server terminal.",[14,293,295],{"id":294},"learning-resource","Learning Resource",[10,297,298],{},"For a deeper dive into building these servers with Node.js, I found this tutorial really helpful:",[22,300,301,309],{},[25,302,303,304],{},"YouTube video: ",[72,305,308],{"href":306,"rel":307},"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=1acKGwbby-E&feature=youtu.be",[76],"Building TCP and UDP servers with NodeJS",[25,310,311,312],{},"Blog Post : ",[72,313,314],{"href":93},"Understanding TCP and UDP",[316,317,318],"style",{},"html pre.shiki code .s7eDp, html code.shiki .s7eDp{--shiki-default:#6F42C1}html pre.shiki code .sYBdl, html code.shiki .sYBdl{--shiki-default:#032F62}html pre.shiki code .sgsFI, html code.shiki .sgsFI{--shiki-default:#24292E}html pre.shiki code .sYu0t, html code.shiki .sYu0t{--shiki-default:#005CC5}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sD7c4, html code.shiki .sD7c4{--shiki-default:#D73A49}",{"title":93,"searchDepth":81,"depth":81,"links":320},[321,322,323,324,325,326],{"id":16,"depth":162,"text":17},{"id":36,"depth":162,"text":37},{"id":54,"depth":162,"text":55},{"id":126,"depth":162,"text":127},{"id":210,"depth":162,"text":211},{"id":294,"depth":162,"text":295},"2024-09-29","A clear explanation of TCP and UDP — how they differ, when to use each, and how these transport-layer protocols power everything from web browsing to video streaming.",false,"md",null,{},true,"\u002Fblogs\u002Ftcp_udp",{"title":5,"description":328},"blogs\u002Ftcp_udp\u002Findex",[338,339,105,340],"programming language","computer science","github","LAkDoiUmFz-SolzGgCKQaiUwyrOfaQJYVnJggbnjSQY",1782753863787]