We are using symphony in our company and I am trying to send a message to the alert bot in symphony.
Someone sent me a small python script which does this already which uses the socket library.
They send the message as socket.send(msg) using import socket in their script.
Question is : what is socket.send comparable with in kdb ? It's not a http post so it's not the .Q.hp .. Is this similar -> {h:hopen hsym`$"host:port";h"someMessageCompatibleWithSymbphonyBot";hclose h}
UPDATE: I have been told that my kdb message is not pure tcp. Can anyone point me in the right direction?
hopen works for kdb-to-kdb, not kdb-to-other so yes in that sense it's not pure tcp.
Normally when kdb needs to communicate with another system by tcp you would use some sort of middleman library to handle the communication layer.
In theory you could use the python script/package in your kdb instance if you use one of the numerous kdb<>python interfaces (pyq, embedpy, qpython etc)
Related
Back in the javascript world there is a library all the socket part called socket.io
the way it works is by send and receiving the data by and events.
for example: the server can send to the client an event called "msg_received" with the message itself as the data.
in python it seems to not be as asynchronous as its in javascript. its also not working with events but only with strings which is a bit diffrent than how i use to work with the sockets.
i.e socket.send(<string>), socket.recv(<integer>)
i would love if anyone could put some light the issue to explain to me how it works in python since i've searched all over the internet and couldn't find an answer.. or point me to a similar library like the one i mentioned above.
I want to send a request to a server which is a private protocol based on TCP (Not HTTP), How Can I send a request using Python?
Python sockets are what you are looking for. Take a look at the Python Socket class at https://docs.python.org/2/library/socket.html
This site includes examples of how to set up a server and client and provides a basic example of the fundamental TCP Communication using Python. If you need something with more control you may want to look at Scapy: http://www.secdev.org/projects/scapy/
Scapy is a python implementation that provides a framework to control almost all aspects to Network Communication all the way down to Layer 2 (Ethernet Frame).
I'm trying to set up a simple client to server interface for calling functions/programs on the server. A client will send a simple command to the server listening for such commands. Once the server receives a command from the client it will execute the following function or program on the server. I have looked into a simple TCP server receiving a text string and parsing that string then executing the a function or external program. I have read into using XML-RPC implemented with a twisted server as well.
What I'm asking is which would be the easiest to set up or are there any other ways to easily do this task?
Thanks.
There is a great tutorial for twisted that will do just fine as a teaching tool (and guide you by hand in writing a basic server/client services). Have a go at it http://twistedmatrix.com/documents/current/core/howto/tutorial/ what you will probably want to do is parse received info and act accordingly.
If it is appliable in your case, maybe you can use full-featured system for async/remote job execution like Celery?
There are more than one way to achieve your requirement ach with some pros and cons:
Python Low Level Sockets
Using Standard python socket libraries and cliet server architecture
Connecting to Server via protocols like Telnet/SSh and then triggering some code.
Using Python libraries like Telnet/ssh or Subprocess.
XML-RPC
Sending a XMP RPC request as described here http://docs.python.org/2/library/xmlrpclib.html
In my opinion easiest method to achieve remote method triggering is via Python Subprocess Module. I generally use following kind of syntax for my general purposes.
import subprocess
ret = subprocess.call(["ssh", "user#host", "program"]);
# or, with stderr:
prog = subprocess.Popen(["ssh", "user#host", "program"], stderr=subprocess.PIPE)
errdata = prog.communicate()[1]
Hope it helps
I am trying to create a server in Python 2.7.3 which sends data to all client connections whenever one client connection sends data to the server. For instance, if client c3 sent "Hello, world!" to my server, I would like to then have my server send "Hello, world!" to client connections c1 and c2. By client connections, I mean the communications sockets returned by socket.accept(). Note that I have tried using the asyncore and twisted modules, but AFAIK they do not support this. Does anybody know any way to accomplish this?
EDIT: I have seen Twisted, but I would much rather use the socket module. Is there a way (possibly multithreading, possibly using select) that I can do this using the socket module?
You can absolutely do this using Twisted Python. You just accept the connections and set up your own handling logic (of course the library does not including built-in support for your particular communication pattern exactly, but you can't expect that).
I'm having a difficult time fully understanding the nature of a TCP server/client relationship when a JSON string is sent to the server. The information I need may be out there, but I'm perhpas not using the correct search paramaters as I'm looking.
I've built a Python TCP, JSON-RPC Server from the following examples:
https://github.com/joshmarshall/jsonrpclib
http://code.activestate.com/recipes/552751-json-rpc-server-and-client/
In both cases, I can communicate with the Python server from a Python console on a different computer, sending commands from one (the client) to the other (server). In all of the examples, I've had to install the libraries mentioned above on both the client and the server machines in order to facilitate the TCP communication.
So the background to my situation and question is, when does JSON enter the mix? This is what I want to do:
Setup a Python TCP server that accepts a JSON string from a remote client inside (or outside) the network. The server parses the JSON string, fetches the method and parameters from the objectified string, and executes the method. The server then sends a JSON string result to the calling client. In this case, the client is a mobile application (iPad, Android, etc) with a JavaScript library that I'll use to send the requests to the server.
Why would I need a Python client? From what I can gather, the client just needs to open a connection to the server and then send the JSON string, right? Why do all the code samples include Python client examples? Are they assuming a server machine is going to talk to a server machine, so they have included client code to help generate the JSON string that will be sent to the server?
If I assume that a Python client isn't really needed for anything, I've been sending JSON strings to the Python server from the iPad, but in each case the server is reporting a "Bad request syntax" error. I'll pen a new question on that issue if I'm understanding the current question correctly.
Insight is appreciated.
The JSON encoding is the lingua franca of your RPC protocol, so you can indeed use any client you like. The implementations you found for JSON-RPC use the HTTP protocol, a very specific communication protocol built on top of TCP/IP, but you can implement the same protocol over raw TCP-IP sockets if so required.
The examples include both the Python client and the server because they illustrate how to implement the JSON-RPC standard in Python, not in JavaScript or C or Lisp. They focus on the implementation in one language. The JSON-RPC standard however, is language agnostic. It doesn't matter what language you write either the server or the client in, as long as they use the same standard.