01110100110101010101011101100010
Posts tagged Simple
small epoll wrapper
Mar 13th
I remember my first encounter with epoll some time back trying to get a simple server working, implementing a proxy and then a few days back i saw one of my friend trying to get started with epoll, which made me think it will be good to have a simple wrapper around epoll which will allow me to get started with the application and not worry about epoll specifics and at the same time providing enough control, so i wrote a small wrapper with callbacks, which has been quite helpful for my epoll usage, here is the interface poll.h
code and a sample can be found on github
PS – just checkout libevent which is an awesome battle tested event notification library, and a quick getting started
Simple hash tables in c
Mar 11th
I was working on a code where i had to lookup a structure based on the file descriptor (socket) again and again in a code, i was using a linked list initially but as the nodes grew i knew i should use a hash table, so i wrote a simple hash table implementation which did the work.
its a just works implementation there are a lot of thing which can be added like a perfect hash function but as long as hash table is not the bottle neck this should work, code can be found on github
file hashtable.h contains the definition
More >
Creating a Simple Chat Application with Python
May 1st
Creating application with Python is very simple, here is a simple chat application made by using the socket module, it has 2 parts First Server and Second client, you run the server first and then connect the client to it, here is the code
Here is the Server Code
#!/usr/bin/env python
from socket import *
from time import time, ctime
IP = ''
PORT = 23456
ADS = (IP, PORT)
tcpsoc = socket(AF_INET, SOCK_STREAM)
tcpsoc.bind(ADS)
tcpsoc.listen(5)
while 1:
print "Waiting for connection"
tcpcli, addr = tcpsoc.accept()
print "connected from:", addr
while 1:
data = tcpcli.recv(1024)
if not data : break
print data
data1 = raw_input(">>")
if data1 == "q;t": break
tcpcli.send(data1)
tcpcli.close()
tcpsoc.close()
Here is the client code
#!/usr/bin/env python
from socket import *
IP = ''
PORT = 23456
ADS = (IP, PORT)
tcpsoc = socket(AF_INET, SOCK_STREAM)
tcpsoc.connect(ADS)
while 1:
data = raw_input("msg>>")
if not data : break
tcpsoc.send(data)
data = tcpsoc.recv(1024)
if not data: break
print data
tcpsoc.close()
the code above might not be properly intended so you can download the code from http://fb.ankurs.com/tcp_server.py and http://fb.ankurs.com/tcp_client.py
enjoy!!!



