Coder Social home page Coder Social logo

sockets-lab's Introduction

code for creating sockets

For teaching/learning about sockets, playing with the underlying TCP transport layer communications. TCP is the transport used for a lot of application layer protocols.

If you would like to try this you will need to install (or check for)

  1. Python V 3 (preferred) python3 --version or python --version
  2. netcat nc on *nix

echo server

see server.py when you run the server the process logs to socket.log (it appends, does not overwrite so you may want to delete old versions as needed)

server side

Run the server code, it will bind to tcp (stream) & ip & port

  • run in background ./server.py &
    • binds to 127.0.0.1:8111
    • check it with netstat -lan |less note the state LISTEN
    • if it crashes or has just ended the ip&port may still be bound, in a TIME_WAIT status instead of LISTEN, you can see this through netstat, you will have to wa,it for it to end
    • you can see the comms via socket.log in the cwd

client side, talk to server

On the same system, use netcat (nc) to act as a client & make the socket pair

  • fake out client comms with netcat
    • talk to the server nc -v -n 127.0.0.1 8111
    • it will echo the data you type in back at you, as long as the socket pair is live
    • quit will end the connection on the server side
    • you will have to hit enter again after entering quit as that will signal nc to stop
    • check the socket source & dest while you are talking to the server netstat -lan|less and after you quit (you may see TIME_WAIT)

Use the code in a lab exercise

Follow the instructions in lab-questions to play with and learn about TCP sockets.

Teacher's version in

restricted, gitlab

sockets-lab's People

Contributors

campbe13 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.