首页 >> 民生舆情

Erlang与Python间的socke节能

民生舆情  2020-11-07 00:54 字号: 大 中 小

Server 端:

-module(eserver).

-author("hanzhupeng@").

-export([startd/0, start/0,start/1,process/1]).

-define(defPort,2000).

startd() -

register(eserverp, spawn(?MODULE, start, [])).

start() - start(?defPort).

start(Port) -

case gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}]) of

还是会对观察和实践“中国式管理”平添几分裨益吧。集体主义的挂画和个人主义的暗门记得曾经读过一篇国外学者关于中国式管理的论文

{ok, LSock} - server_loop(LSock);导致气溶胶的湿沉降减弱。

{error, Reason} - exit()

end.

%% main server loop - wait for next connection, spawn child to process it

server_loop(LSock) -

case gen_tcp:accept(LSock) of

{ok, Sock} -

spawn(?MODULE,process,[Sock]),

server_loop(LSock);

{error, Reason} -

exit()

end.

%% process current connection

process(Sock) -

Req = do_recv(Sock),

Resp = "hello world",

do_send(Sock,Resp),

gen_tcp:close(Sock).

%% send a line of text to the socket

do_send(Sock,Msg) -

case gen_tcp:send(Sock, Msg) of

ok - ok;

{error, Reason} - exit(Reason)

end.

%% receive data from the socket

do_recv(Sock) -

case gen_tcp:recv(Sock, 0) of

{ok, Bin} - binary_to_list(Bin);

{error, closed} - exit(closed);

{error, Reason} - exit(Reason)

end.

Python Client端

import socket

HOST = 'localhost' # The remote host

PORT = 6889 # The same port as used by the server

s = cket(_INET, CK_STREAM)

nnect((HOST, PORT))

nd('Hello, world')

data = cv(1024)

ose()

print 'Received', repr(data)

惠州看白癜风医院哪家好
临夏白癜风专科医院
癫痫
推荐资讯