我有一个如下所示的客户端 scala 代码
import java.net._
import java.io._
import scala.io._
import scala.pickling._
import scala.pickling.json._
val sk = new Socket(InetAddress.getByName("localhost"), 13373)
val output = new PrintStream(sk.getOutputStream())
val textRDD = sc.textFile("some file");
output.println( #pickle the textRDD and pass it to server)
output.flush()
sk.close()
和 python server.py 如下所示,
import SocketServer
import json
import pickle
class MyTCPServer(SocketServer.ThreadingTCPServer):
allow_reuse_address = True
class MyTCPServerHandler(SocketServer.BaseRequestHandler):
def handle(self):
try:
data = self.request.recv(1024)
#unpickle the data received here and print it.
print data
except Exception, e:
print "Exception wile receiving message: ", e
server = MyTCPServer(('127.0.0.1', 13373), MyTCPServerHandler)
server.serve_forever()
如何在 scala 客户端中腌制 TextRDD 文件并将其传递给 python 服务器以取消腌制并打印接收到的数据?