2
$\begingroup$

I am teacher in high school, and I would like to teach socket programming. How can I teach socket programming?

$\endgroup$
3
  • 4
    $\begingroup$ 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. $\endgroup$
    – ggorlen
    Apr 8, 2023 at 5:10
  • $\begingroup$ 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: 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. $\endgroup$
    – Clive Long
    Apr 11, 2023 at 16:45
  • 2
    $\begingroup$ Isn't this too advanced for highschooler ? $\endgroup$ Apr 14, 2023 at 10:21

4 Answers 4

3
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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 $\endgroup$
    – user253751
    May 5, 2023 at 3:20
3
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ 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 $\endgroup$
    – Rushi
    Apr 29, 2023 at 3:15
  • 1
    $\begingroup$ I guess it's this 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. $\endgroup$
    – Rushi
    Apr 29, 2023 at 3:21
  • $\begingroup$ @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. $\endgroup$ Apr 29, 2023 at 8:01
  • $\begingroup$ I've put a comment in the chatroom. Can you see it? $\endgroup$
    – Rushi
    Apr 29, 2023 at 8:08
3
$\begingroup$

(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, 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.

$\endgroup$
1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.