Simple HttpServer in Twisted Python
this is a sample code of http server programmed in twisted python
#httpserver.py
#!/usr/bin/python
import sys
from twisted.protocols import basic
from twisted.web import server,resource,http
from twisted.internet.protocol import Protocol
class HttpProtocol(basic.LineReceiver,Protocol):
def __init__(self):
self.lines = []
def connectionMade(self):
self.sendLine(“HTTP/1.0 200 OK”)
self.sendLine(“Content-Type:text/plain”)
self.sendLine(“”)
def lineReceive(self,line):
# your code goes here: process the line you receive
print line
class HttpFactory(http.HTTPFactory):
def __init__(self):
self.protocol = HttpProtocol
def onClientConnected(self):
print “Connected”
reactor.listenTCP(8080,HttpFactory())
reactor.run()
running on the terminal
$ python httpserver.py
as the reactor.run called, your http server is now listening on port 8080
List of All Programming Languages
Helloworld in all programming language
ActionScript
AdaLanguage:
AlephLanguage:
AppleScript
AssemblyLanguage for the IBM-PC (i386):
AwkLanguage:
B (BeeLanguage):
BasicLanguage
BefungeLanguage:
Bourne Shell:
BrainfuckLanguage (an EsotericProgrammingLanguage)::
C (CeeLanguage) (according to KernighanAndRitchie):
CsharpLanguage:
C++ (CeePlusPlus)
Cobol
ColdFusion
RM COBOL
COW (an EsotericProgrammingLanguage):
D
DOS (DiskOperatingSystem)
EiffelLanguage
ErlangLanguage:
EtcLanguage:
Forte TOOL:
ForthLanguage:
FrinkLanguage
GoogleplexianLanguage:
HaskellLanguage
HqNinePlusLanguage
HtagLanguage
HTML
InformLanguage
IoLanguage
JavaLanguage:
Swing Java
JavaApplet:
JavaScript:
J (JayLanguage)
JoyLanguage:
K (KayLanguage)
LingoScriptingLanguage
Logo
LolCode:
LuaLanguage:
LxLanguage:
MicrosoftExcel
ModulaThree
NemerleLanguage: (http://www.nemerle.org)
OpalLanguage
ObjectiveCaml
PascalLanguage
PathLanguage
PerlLanguage
PerlInline
PhpLanguage
PlbLanguage (or Databus)
PowerScript
PowerShell
PrographLanguage
Prolog
PythonLanguage
QBasic
Rebol
RexxLanguage
RpgLanguage
RubyLanguage
ShellScript
SchemeLanguage
SmalltalkLanguage
SmlLanguage
SnobolLanguage
TeX
TomLanguage
ToolCommandLanguage
UnLambdaLanguage
VisualBasic
VisualFoxPro
MS VJ++
VoiceXml
Whirl
VBScript
JScript
WikiWiki
Send Message in J2ME
Sample code for sending a message using J2ME: You can send message with or without port.
MessageConnection smsconn = null;
try {
/** Open the message connection. */
smsconn = (MessageConnection)Connector.open(address);
TextMessage txtmessage =
(TextMessage)smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
txtmessage.setAddress(address);
txtmessage.setPayloadText(messageBox.getString());
smsconn.send(txtmessage);
} catch (Throwable t) {
t.printStackTrace();
}
if (smsconn != null) {
try {
smsconn.close();
} catch (IOException ioe) {
System.out.println(“Closing connection caught: “);
ioe.printStackTrace();
}
}
Start the Midlet when New Message arrived
If you want your midlet to start when incoming message arrived, the message should be sent with specific port where your midlet is listening.
Your jad file should look like this
MIDlet-Jar-URL: MyMidlet-0.0.1.jar
MIDlet-Jar-Size: 556255
MIDlet-Name: MyMidlet
MIDlet-Vendor: 3rd Brand Pte Ltd.
MIDlet-Version: 0.0.1
MIDlet-1: com.MyMidlet
MIDlet-Push-1: sms://:5000,MyMidlet,*
MIDlet-PortNumber: 5000
MIDlet-Permissions: javax.microedition.io.PushRegistry,javax.wireless.messaging.sms.receive
But your midlet does not automatically start when new message arrive.. It will ask you if you want to start your midlet.