Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
jermanojunior

Python Socket programming

Recommended Posts

Posted · Original PosterOP

Hi , I need some help in socket programming, could anyone here tell me how can I make something like a client querying data from the server (maybe a dictionary storing stock and their prices) send data from server to the client (according to the request like stock first and then prices maybe price of multiple stocks at a time). Can I also make the data look in a tabular form as well on the client end?

I'm at the point where I have done simple client-server code did played with dictionary and tried sending it over to the client but comes as a single vertical line not in a tabular form, is this even possible? I'm fairly new to python so..

 

1. How to send rows of data to the client instead of a single vertical line maybe two columns and display like a tabular format to the client?

2. sometimes I do not get all the items in the dictionary stored at the server when I type and send the keyword from the client script to the server script, so i have to type n send the keyword like two times atleast to receive all the items ( Using TCP socket here ).

3. After the first packet I send, the next reply I always receive is of the previous query I sent.

 

New to python.. 

Note: both scripts are on the same machine running python2.7

Link to post
Share on other sites
10 minutes ago, jermanojunior said:

1. How to send rows of data to the client instead of a single vertical line maybe two columns and display like a tabular format to the client?

2. sometimes I do not get all the items in the dictionary stored at the server when I type and send the keyword from the client script to the server script, so i have to type n send the keyword like two times atleast to receive all the items ( Using TCP socket here ).

3. After the first packet I send, the next reply I always receive is of the previous query I sent.

1) You can use a list of lists, or send the data in a single list and interpret it inside the client; for example, if your data is ("fruits", "veggies", "apple", "spinach") you could consider every even index to be one column and every odd index to be another column - or use suitable intervals depending on how many columns you want.

2) Sounds like a bug in the server, can't help you without seeing the code

3) Same as 2)


...is there a question here? 🤔

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to post
Share on other sites
Posted · Original PosterOP

I did use list of lists but got to know they can only exchange packets of strings and not lists so had to convert the list to string and then send, and it outputs just like the dictionary in a single vertical line. Did you mean to change the received string to list again once received?

Link to post
Share on other sites
7 hours ago, jermanojunior said:

I did use list of lists but got to know they can only exchange packets of strings and not lists so had to convert the list to string and then send, and it outputs just like the dictionary in a single vertical line. Did you mean to change the received string to list again once received?

When I have to send a list as data outside of the scope of the program, I tend to simply append each element of the list separated by a comma. Then it can easily be put back into a list by separating elements at each comma.


NetBeans is cancer. 

NetBeans is cancer. 

NetBeans is cancer. 

NetBeans is cancer. 

NetBeans is cancer. 

NetBeans is cancer. 

Link to post
Share on other sites
16 hours ago, jermanojunior said:

I did use list of lists but got to know they can only exchange packets of strings and not lists so had to convert the list to string and then send, and it outputs just like the dictionary in a single vertical line. Did you mean to change the received string to list again once received?

I would use json

 


{

    Data: [

        { name: 'LTT', price: 25.67},

        { name: 'YoutTube', price: 35.67}

    ]

}

 

You can data.toString()  the json to sent and then JSON.loads it the other side.

 

That's json from JavaScript I think python requires all keys to be quoted too.


                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×