Jim's
Tutorials

Spring 2018
course
site

Jim says

The client/server code is a good exploration - you got things to work and are seeing some of the issues.

I don't see the sort of specific protocol invention that I had asked for, something like a simple tic-tac-toe or guessing game interaction with a specific set of expectations on both sides.

Leslie says

I made a socket chat program that allows two clients to connect and exchange messages. Below is the final output:

>>>python clientTest.py
>>>hello, welcome to chat, at any point type quit if you would like to end convo. please type your name
>>>wilson
>>>hello wilson, and leslie, let's begin chat!
>>>Type your message! hi there
>>>wilson:  hi there
>>>leslie:  why hello, nice to meet you

..and for the other client window (the other side of the conversation)

>>>hello wilson, and leslie, let's begin chat!
>>>Type your message! why hello, nice to meet you
>>>wilson:  hi there
>>>leslie:  why hello, nice to meet you

and you type "quit" to quit the chat:

>>>Type your message!quit
>>>the chat is ending, goodbye!

NOTE: both users need to say quit in order for the program to stop, and it just results in an error after asking for another input, so that needs to be improved but fiddled w it for a few hours and left it alone.

All in all, getting this to run was a very interesting experience. It mostly involved really keying in on the flow of the messages/connections, so I could properly ping things back and forth. The way it is currently set up, I have two clients sending messages to a server which is then broadcasting the messages to each client, so they can have a conversation. You need to run serverTest.py, wait for it to start listening, then run clientTest.py in one window in terminal and run it again in another window. Only when two connections are established does the server spawn a new thread and the testchat function asks for each client to enter an input.

I'd say the most difficult part of the process was orchestrating different functions to happen within these client/server/client interactions. I tried a number of different techniques to get even the most basic dialogues going between them. I began by reading this source : Lets Write a Chat App in Python https://medium.com/swlh/lets-write-a-chat-app-in-python-f6783a9ac170. You'd think this would have solved all my problems but it only just led me further down into a rabbit hole of functions I could almost get to work but not quite. I kept a lot of those in my original files, commented out, so you can look a bit at the process. In other words, I began by over-complicating this thinking what I was trying to do was relatively simple but it was not that easy. I then re-did everything to keep just the bare-minimum functionality(can I get a message from client to client?) and that helped. I formatted the way everything would print after that.

Some other resources I used included this conversation in Stack Overflow: How to make the Set command not wait for an answer?- https://stackoverflow.com/questions/24064970/how-to-make-the-set-command-not-wait-for-answer and: Client and Server Unable to Establish a Connection-https://stackoverflow.com/questions/13108441/client-and-server-unable-to-exchange-data-python

I also looked at this: Sending String via Socket: https://stackoverflow.com/questions/21233340/sending-string-via-socket-python/21233499

And found this to be quite helpful: Geeks for Geeks Socket Programming in Python- https://www.geeksforgeeks.org/socket-programming-python/

WIRESHARK:

RESOURCES: Understanding TCP Sequence- http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/

Textbook- Computer Networking: Internet Protocols in Action

I ran Wireshark after successfully making these connections- see the screenshots below. I selected the Loopback filter in wireshark to see the messages I was sending to myself. There were some mysterious things being sent to myself right off the bat, did some investigating and it turns out my phone was talking to my computer so I had to turn that off. I ran the client and server files, and wow, saw some pretty cool things. First of all I needed to organize what I saw by protocol because I knew I was using TCP sockets. I could see the port numbers (mine, 12346) and that of one client and another, talking back and forth. I saw the code SYN as I was first making the connections. I saw the ACK, acknowledge alerts. When I saw "PSH" it told me there was data in there being passed along. I could even see the message being passed (I include that in my screenshots). I also saw the FIN and ACK that the FIN was received, after typing quit into my program in terminal. All in all, I'm convinced theres something to this wireshark business after having done the reading and done several experiments of my own. In conclusion, I want to become a hacker and use this knowledge for practical purposes in the not so distant future.

https://cs.marlboro.college /cours /spring2018 /jims_tutorials /web_tech /may5
last modified Mon June 24 2024 12:42 am

attachments [paper clip]

  last modified size
TXT Screen_Shot_2018-05-05_at_3.41.54_PM.png Mon Jun 24 2024 12:42 am 1.0M
TXT Screen_Shot_2018-05-05_at_3.42.17_PM.png Mon Jun 24 2024 12:42 am 176K
TXT Screen_Shot_2018-05-05_at_3.42.40_PM.png Mon Jun 24 2024 12:42 am 244K
TXT clientTest.py Mon Jun 24 2024 12:42 am 1.6K
TXT functiontest2.py Mon Jun 24 2024 12:42 am 2.4K
TXT serverTest.py Mon Jun 24 2024 12:42 am 2.7K