![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
I/O proccessing
hi again, seems im requesting a reasonable amount of help already. Anyways here goes.
My script needs to both send and receive data from sockets, however. It is not a case of it is know when data is going to be received. So how would i go about receiving data from sockets and printing to the screen without interupting the input system. Currently i have set up a threading system to deal with all income data from the connected socket. However attempts to print this information to the screen are with little success, as the main section of the program is constantly running input commands apart from milliseconds taken to process the information inputted. The only other way around this would be to create another script and begin streaming data between the two. For instance main script -- all input occurs here and is sent via sockets PC A sends data to main script main script -- relays information to new script titled A, which then proccess all data sent from PC A PC B sends data to main script main script -- relays information to new script titled B, which then proccess all data sent from PC B ... but that would mean that all input would have to be specifing which PC to send the data to for instance to send 'hi' to PC B i would have to use something like /send PCB hi as the input string, and all of these would occer from the main script no matter what PC it is to be sent to. so for sending large numbers of data it becomes very tedious and time consuming. As well as messy and confusing. the latter half is not much the problem with having to send all strings via the mainscript window. However i would very much like input on methods of taking I/O at the same time. Thanks |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: I/O proccessing
You need to print to the screen as you're taking user input? Yikes. That's what you use a GUI for. I've never seen this accomplished with a console. It's probably possible, but I don't know how stable it would be.
My main concern is over what will happen if the user tries to press buttons while you are outputting to the screen. You don't want to echo that data in the output. If there's a way to stall the echo of the user-input at the top of a print wrapper, and then release it after the print wrapper is done, it might be more feasable. Seems nasty, and obviously OS-dependent. I am hoping someone here can give you a library or piece of code that does this already, but I would be surprised if it's that common. Why not use a GUI? |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
Re: I/O proccessing
I did think of another method which is a bit bizzare but, well as im new to python im trying to work through step by step, making my program based on consoles, then once i start nearing completion i indtend to look into using Tkinter to program a GUI for it.
My other solution is to open a new script in a different console window, ofcourse indoing this ill have to check OS etc, anyway then the main script receives the call from PC A then launches the new script window which simple reads from a text file, print say last 50 lines to the console then appends user input to the end. The main script would take all data sent to it and rather than echoing it onto the screen it would output it to the file. Then send a simple command to a thread section in the script that is reading the files to tell it to reload the file and then append the input to the end of it once again When the user inputs information this could then be sent back to the min program via the socket connection established between it and the main script which can then forward it to PC A...and then PC A takes appropriate action. This is a possible way, thus neating th whole lot up also as it links the sending of commands to the received commands all to one window with no mixing from other PC's. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: I/O proccessing
The simplicity of Python makes a GUI less daunting than a hacked together solution. GUIs handle all the threading and synchronization between input and output for you. Why reinvent the wheel? Or worse yet, why avoid using that wheel?
I am sure that even though you are new to Python, it would be within your grasp to create a simple frame with an input and output box. |
|
|
|
|
|
#5 | ||
|
Hobbyist Programmer
|
Re: I/O proccessing
Quote:
Quote:
The reason i choose to learn Python was for the very reason it was simple and i wanted to look into network programming in some language and Python has proven its simplicity for that and the GUI will be an added bonus. Looks like im just going to be skipping down to the GUI section of my project thanks Sane. any suggested Tkinter tutorials? Chris |
||
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: I/O proccessing
Ah, so your GUI is to be more complicated then. I see. Well it's entirely up to you. If someone can suggest some tried-and-true functions to accomplish your original question, there's that route. But as long as you're a quick learner, I think you'll enjoy the GUI route. Remember that there are several toolkits at your disposal, including wxPython, tkinter, PyQt, Iron Python, etc...
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
|
Re: I/O proccessing
I do enjoy the though of GUI indeed im just not so sure about the fast learner part.
Yes im aware of the multiple different toolkits, i also remember trying to install wxPython and getting no where which was not to helpful, any personally recomendation as to which toolkit to use? then i guess ill start reading xD |
|
|
|
|
|
#8 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,799
Rep Power: 5
![]() |
Re: I/O proccessing
I can't make any personal recommendations, since I've only used wxPython and TkInter. But here's a good link that might help you out:
http://wiki.python.org/moin/GuiProgramming It includes information about every toolkit available, tutorials, links to the official sites, and all sorts of good information. |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
|
Re: I/O proccessing
Thanks alot Sane ill check it out, no doubt you'll see some GUI questions around before long
Chris |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stadard C i/o problems with C++ classes | Soulstorm | C++ | 8 | Jul 15th, 2007 9:21 PM |