2

I have documentation on how to use a TCP/IP binary stream API. The attached images show the protocol. I have a working example of this in C#. I want to do this using python instead, as I don't know c# or windows.

I am assuming I would use python sockets, then I have to send the API messages, with payloads looking at this docs.

Could you point me in the right direction to get this going with python?

How would I set it to know this is the authentication message, 0x21 and compress the data etc?

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.sendall(u"{'username':'username', 'password':'password'}".encode('utf8'))

Protocol doc enter image description here enter image description here enter image description here

4
  • 1
    Not sure what is stopping you? You know Python, you know how to implement TCP communication in Python? You have the Protocol docs ... Commented Feb 10, 2017 at 8:58
  • I don't know it that well, I'm unsure how you set encoding, compression etc. Im used to http posts Commented Feb 10, 2017 at 9:00
  • About these two your Docu sais: "Note that the server will use the same as was used to send the client auth message" ( not an exact citation ). So I'd start without compression and whatever suits you best (JSON/BSON). If that works, move on. oh and it also sais "UTF-8" :) Commented Feb 10, 2017 at 9:25
  • Your header has to be setup from bytes according to the docs: 1 byte version, 4 bytes sequence ( big-endian ) ... maybe this will help: stackoverflow.com/a/18311133/982149 Commented Feb 10, 2017 at 10:44

2 Answers 2

2

in OSI model you are above layer 4 (transport, TCP/IP,...) on at least layer 5 (session). there are some examples of implementations of session layer protocols like http, ftp,... i.e. in http://github.com/python-git/python/blob/master/Lib/ftplib.py or http://github.com/python-git/python/blob/master/Lib/httplib.py

as your protocol includes headers maybe http is the better example

to use the TCP/IP API in http protocol see http://www.stackoverflow.com/questions/8315209/sending-http-headers-with-python

import socket

sock = socket.socket()
sock.bind(('', 8080))
sock.listen(5)
client, adress = sock.accept()

print "Incoming:", adress
print client.recv(1024)
print

client.send('HTTP/1.0 200 OK\r\n')
client.send("Content-Type: text/html\r\n\r\n")
client.send('<html><body><h1>Hello World</body></html>')
client.close()

print "Answering ..."
print "Finished."

sock.close()

as far as i can see you skipped the headers (version, sequence, type, encoding, ...) in your code completely you have to add them whenever you send a frame

so try

self.socket.send(...headers...)
self.socket.send(u"{'username':'username', 'password':'password'}".encode('utf8')) // has to be send as JSON ???

see also http://www.stackoverflow.com/questions/22083359/send-tetx-http-over-python-socket

ftp example (no headers...)

    # Internal: send one line to the server, appending CRLF
    def putline(self, line):
    line = line + CRLF
    if self.debugging > 1: print '*put*', self.sanitize(line)
    self.sock.sendall(line)

also see scapy

Sign up to request clarification or add additional context in comments.

Comments

0

I try to use tcp protocol once. You can send authorization values(username ,password ) in all requests.And other data with it exp({'username':'username', 'password':'password','data':'value'}).With this there is no any current standart for data. Many of tcp clients send that data like this #A#:username;password;#D:value\n (A -authorization ,D -data), example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.