Answers.Body: <p>I teach socket programming to undergraduates at university level 5 in the UK (Sophomore) and have done this in multiple languages over a considerable period. This is done as an exercise component in a course unit that covers the layered models, protocol specifications and other theoretical topics.</p>
  <p>It can be taught at another level but the students would need to have some existing coding experience first. The language that you use for the sockets affects the exercise difficulty substantially. I find that C# and Java work satisfactorily whereas it is quite a problem in Python and too detailed in <strong>C</strong>. The differences are due to subtleties in the socket APIs for those languages in areas such as how deadlocks and interrupts are handled which can confuse a novice.</p>
  <p>I have a YouTube Video series which focuses on developing a client-server application using C# which may give an idea on the subject.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-29T03:15:52.003Z
Answers.Text: Can you elaborate a bit on "quite a problem in python"? And a link to the youtube series (maybe in your user page) please! Personal opinion: Pythons coroutine/async model is a disaster. Golang is an ideal fit to the model. And unlike C hi level. C# no experience for this
Answers.UserDisplayName: Rushi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-29T03:21:04.710Z
Answers.Text: I guess it's this https://youtube.com/@BrianTompsett? I am asking because I'm working on documenting how python, seemingly neat for CS1, scales up very poorly for more advanced CS studies.
Answers.UserDisplayName: Rushi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-29T08:01:36.913Z
Answers.Text: @Rusi Yes you have the correct one of my Channels. Elaborating on the issues with Python is beyond this question, so not appropriate here; however it is easy  to get a Python socket program deadlocked in an uninterruptible wait state which is confusing for novices and students alike. I had to write special methods for  my students so they could cope whereas C# works out of the box.
Answers.UserDisplayName: Brian Tompsett - 汤莱恩
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-29T08:08:00.937Z
Answers.Text: I've put a comment in the chatroom. Can you see it?
Answers.UserDisplayName: Rushi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-22T09:18:15.710Z
Answers.LastActivityDate: 2023-04-22T09:18:15.710Z
Answers.UserDisplayName: Brian Tompsett - 汤莱恩
Answers.Body: <p>We are developing a couple units on Sockets for our post-AP students. It is a work in progress.</p>
  <p>We begin with 2-3 days about the OSI model. There are some great videos from Crash Course Computer Science and Code.org about how networks work that you can center around.</p>
  <p>Then for 2-3 days we teach the concept of threading and race conditions.</p>
  <p>Finally, we begin writing some simple client/server Java apps -- beginning with very basic ones that just say hello, to multi-user chat servers that pass Strings as their messages (students have a lab where they need to add new message types), to adding objects that are passed as messages instead of Strings, to creating a networked turn-based JavaFx game like Othello.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-05T03:20:18.163Z
Answers.Text: is it good to teach the OSI model if it has zero practical relevance to the actual tasks? I feel like this kind of thing confuses people. If the goal is to learn socket programming you don't need OSI just like you don't teach cache hierarchy in an introductory C programming course
Answers.UserDisplayName: Criticize SE actions means ban
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-06T15:59:13.903Z
Answers.LastActivityDate: 2023-04-06T15:59:13.903Z
Answers.UserDisplayName: Bryan R
Answers.Body: <p>(am not an educator but) someone I knew had a class where they wrote an IRC client. It is quite a simple protocol, but not too simple, that seems quite good for teaching. The teacher provided the server, and the student was to write a program that would connect to the server, join a channel and allow the user to read messages and send messages. The language was Java (same as the rest of the course).</p>
  <p>IRC is quite a simple protocol, but not too simple. It can be debugged with a screen and keyboard. It seems ideal for learning. The protocol is text-based and looks like <a href="http://chi.cs.uchicago.edu/chirc/irc_examples.html" rel="nofollow noreferrer">this</a>, so an early iteration of the student's program can let them directly interact with the IRC connection, without processing the commands or responses.</p>
  <p>If threads are used, Python's threading model (with the GIL) could make it a better choice as no synchronization is usually needed. But don't make the student learn a new language just for socket programming, obviously.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-05T03:26:45.610Z
Answers.LastActivityDate: 2023-05-05T03:26:45.610Z
Answers.UserDisplayName: Criticize SE actions means ban
Answers.Body: <p>This is very advanced, However.</p>
  <p>Consider using a Unix shell (e.g. <code>bash</code>). Start with (anonymous) pipes. e.g. <code>ls | less</code></p>
  <p>After that, when you need 2-way or remote communication, you can introduce sockets.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-17T20:16:03.133Z
Answers.LastActivityDate: 2023-05-17T20:16:03.133Z
Answers.UserDisplayName: ctrl-alt-delor
Body: <p>I am teacher in high school, and I would like to teach socket programming. How can I teach socket programming?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-08T05:10:13.120Z
Comments.Text: More details about your specific situation would be nice to keep answers relevant for you. What language(s) are you working with? Are you looking for low-level C type stuff or high-level JS/socket.io material? What level are your students at? What curriculum context is this being taught in? Thanks.
Comments.UserDisplayName: ggorlen
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-11T16:45:13.870Z
Comments.Text: I have elementary programming skills in Python. I wanted to write a program that communicated and exchanged data with another program on another machine to make a bit more concrete my rather theoretical knowledge of TCP/IP. I used a guide like: https://realpython.com/python-sockets/ to send a string from on machine to another. The program worked. I learned a lot about program-to-program communication from such a simple program.
Comments.UserDisplayName: Clive Long
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-14T10:21:41.093Z
Comments.Text: Isn't this too advanced for highschooler ?
Comments.UserDisplayName: Qiulang 邱朗
Tags: <programming><networks>
Title: How can I teach socket programming?
ThreadText: # How can I teach socket programming?
  
  (Asked by: username_0 on 2023-04-06)
  
  I am teacher in high school, and I would like to teach socket programming. How can I teach socket programming?
  
  **Tags:** programming, networks
  
  > **Comments:**
  > **username_1**: More details about your specific situation would be nice to keep answers relevant for you. What language(s) are you working with? Are you looking for low-level C type stuff or high-level JS/socket.io material? What level are your students at? What curriculum context is this being taught in? Thanks.  
  > **username_2**: I have elementary programming skills in Python. I wanted to write a program that communicated and exchanged data with another program on another machine to make a bit more concrete my rather theoretical knowledge of TCP/IP. I used a guide like: https://realpython.com/python-sockets/ to send a string from on machine to another. The program worked. I learned a lot about program-to-program communication from such a simple program.  
  > **username_3**: Isn't this too advanced for highschooler ?  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_4 on 2023-04-22. Score: 3
  
  I teach socket programming to undergraduates at university level 5 in the UK (Sophomore) and have done this in multiple languages over a considerable period. This is done as an exercise component in a course unit that covers the layered models, protocol specifications and other theoretical topics.
  
  It can be taught at another level but the students would need to have some existing coding experience first. The language that you use for the sockets affects the exercise difficulty substantially. I find that C# and Java work satisfactorily whereas it is quite a problem in Python and too detailed in **C**. The differences are due to subtleties in the socket APIs for those languages in areas such as how deadlocks and interrupts are handled which can confuse a novice.
  
  I have a YouTube Video series which focuses on developing a client-server application using C# which may give an idea on the subject.
  
  > **Comments:**
  > **username_5**: Can you elaborate a bit on "quite a problem in python"? And a link to the youtube series (maybe in your user page) please! Personal opinion: Pythons coroutine/async model is a disaster. Golang is an ideal fit to the model. And unlike C hi level. C# no experience for this  
  > **username_5**: I guess it's this https://youtube.com/@BrianTompsett? I am asking because I'm working on documenting how python, seemingly neat for CS1, scales up very poorly for more advanced CS studies.  
  > **username_4**: @Rusi Yes you have the correct one of my Channels. Elaborating on the issues with Python is beyond this question, so not appropriate here; however it is easy  to get a Python socket program deadlocked in an uninterruptible wait state which is confusing for novices and students alike. I had to write special methods for  my students so they could cope whereas C# works out of the box.  
  > **username_5**: I've put a comment in the chatroom. Can you see it?  
  
  ---
  
  ### Answer by username_6 on 2023-04-06. Score: 3
  
  We are developing a couple units on Sockets for our post-AP students. It is a work in progress.
  
  We begin with 2-3 days about the OSI model. There are some great videos from Crash Course Computer Science and Code.org about how networks work that you can center around.
  
  Then for 2-3 days we teach the concept of threading and race conditions.
  
  Finally, we begin writing some simple client/server Java apps -- beginning with very basic ones that just say hello, to multi-user chat servers that pass Strings as their messages (students have a lab where they need to add new message types), to adding objects that are passed as messages instead of Strings, to creating a networked turn-based JavaFx game like Othello.
  
  > **Comments:**
  > **username_7**: is it good to teach the OSI model if it has zero practical relevance to the actual tasks? I feel like this kind of thing confuses people. If the goal is to learn socket programming you don't need OSI just like you don't teach cache hierarchy in an introductory C programming course  
  
  ---
  
  ### Answer by username_7 on 2023-05-05. Score: 3
  
  (am not an educator but) someone I knew had a class where they wrote an IRC client. It is quite a simple protocol, but not too simple, that seems quite good for teaching. The teacher provided the server, and the student was to write a program that would connect to the server, join a channel and allow the user to read messages and send messages. The language was Java (same as the rest of the course).
  
  IRC is quite a simple protocol, but not too simple. It can be debugged with a screen and keyboard. It seems ideal for learning. The protocol is text-based and looks like [this](http://chi.cs.uchicago.edu/chirc/irc_examples.html), so an early iteration of the student's program can let them directly interact with the IRC connection, without processing the commands or responses.
  
  If threads are used, Python's threading model (with the GIL) could make it a better choice as no synchronization is usually needed. But don't make the student learn a new language just for socket programming, obviously.
  
  
  ---
  
  ### Answer by username_8 on 2023-05-17. Score: 1
  
  This is very advanced, However.
  
  Consider using a Unix shell (e.g. `bash`). Start with (anonymous) pipes. e.g. `ls | less`
  
  After that, when you need 2-way or remote communication, you can introduce sockets.
  
  
  ---
  
  