######
server.py#!/usr/bin/python
# coding=utf8
import sys
import os
from socket import *
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol,TCompactProtocol
from thrift.server import TServer
sys.path.append(os.path.dirname(__file__)+"agent")
sys.path.append(os.path.dirname(__file__)+"zipkincore")
sys.path.append(os.path.dirname(__file__)+"jaeger")
from agent import Agent
from zipkincore.ttypes import Span
from jaeger.ttypes import Batch
class Handler(object):
def emitZipkinBatch(spans):
print(233)
#for item in spans:
#print item.trace_id
#print
item.name def emitBatch(batch):
print(233)
#for item in batch:
def tbuffserver():
transport = TSocket.TServerSocket(port=5775, socket_family=AF_INET)
#transport = TSocket.TServerUDPSocket("127.0.0.1", 5775)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
#pfactory = TCompactProtocol.TCompactProtocolFactory()
handler = Handler()
processor = Agent.Processor(handler)
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
print('Starting the server...')
server.serve()
print('done.')
def creatsock():
sock = socket(AF_INET, SOCK_DGRAM)
#sock.bind(("0.0.0.0", 6831))
sock.bind(("0.0.0.0", 5775))
while True:
data = sock.recvfrom(65000)
print data
if __name__ == "__main__":
#creatsock()
tbuffserver()
logger.warning(__name__)