473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to read data from a socket given a file descriptor

Hi,
I'm writing some code using PyGTK2 that uses inpu_add_full() to watch a
socket. I've included the code below. I have two questions:

1) What does a condition == 16 mean? It does match any of the
gtk.gdk.INPUT_* values. What is the use of the condition variable in the
callback?

2) The source variable in the call back is an fd. I have some trivial code
that is able to read from a socket:

while 1:
sock.listen(1)
conn = sock.accept()[0]
got = conn.recv(20)
if (got == 'close'): break
conn.send('hello there %d' % (c))
c += 1

But how can I make this work when I get an fd?

Thanks,

--%<-------------------------------------------------------

def process_socket_message(source, condition):

if condition == gtk.gdk.INPUT_READ:
print 'something to read'
elif condition == gtk.gdk.INPUT_WRITE:
print 'ok to write'
elif condition == gtk.gdk.INPUT_EXCEPTION:
print 'an exception occured on the socket'
else:
print 'I dont know what the condition means'

conn = sock.accept()[0]
got = conn.recv(20)
print got
return gtk.TRUE

if __name__ == '__main__':

gnome.init('xxx','xxx')
widgets = WidgetsWrapper('gui.glade','toplevel', TopLevelHandlers)

# set up the socket to get messages from a client
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.bind('/tmp/mysocket')

# setup and input_add
socket_handler_id = gtk.input_add_full(sock, gtk.gdk.INPUT_READ, process_socket_message)

gtk.mainloop ()
Jul 18 '05 #1
0 1447

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rune | last post by:
Hi, I've written a very simple 'kill-server' to help me shut down processes through Telnet or HTTP. The kill-server is a function and is launched as a thread. I use the module socket.py on Python...
1
by: Patrick LeBoutillier | last post by:
Hi all, I'm trying to perform read and write I/O on a socket file descriptor received for another process via a Unix Domain Socket. In trying to understand all this I came up with a small test...
7
by: Dario | last post by:
I have an unmanaged library that handle many TCP/IP connections. In my .NET application i want to test if there is input available on these connections. Using an existing function of the unmanaged...
4
by: GVK | last post by:
Hi, I'm facing another problem with my network program. I'm writing a basic server that handles multiple clients. Whenever a client is connected, a new thread is created to handle it. The socket...
5
by: Jens | last post by:
Hello, I have been looking for some C-code which listens on a user-defined port for incoming data traffic. When data is received, the data is written to a file. I found some C-code (server)...
8
by: M.Endraszka | last post by:
Hi, I am writing a simple irc-like server and came across weird behavior while debugging. Could anyone tell me why the following happens : I have a class which stores pipe descriptors as a...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
2
by: Dave13 | last post by:
Hi there Below is a small bit of test code for a project im working on, eventually the programs going to be a simple file transfer system, reading a file and then sending it out of a socket, but...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.