c++服务器怎么用firefly

c++服务器怎么用firefly,第1张

使用firefly-admin.py createproject testserver,创建echo测试服务器,代码片段如下,不再累赘:

#coding:utf8

from firefly.server.globalobject import netserviceHandle

@netserviceHandle

def echo_111(_conn,data):

print data

return data

C++程序部分:

======================================================

定义一个结构体:

#include <PshPack1.h>

typedef struct tagtestpack

{

char head[4] // 四字节协议头.

char protover// 版本

unsigned int serverver//??

unsigned int msglen // msglen=len(msg)+4

unsigned int cmdid // 命令id,

char msg[5]//"hello"// 测试数据.

} testpack

#include <PopPack.h>

#include "stdafx.h"

#include <windows.h>

#include <WinSock2.h>

#include <PshPack1.h>

typedef struct tagtestpack

{

char head[4]

char protover

unsigned int serverver

unsigned int msglen

unsigned int cmdid

char msg[5]//"hello"

} testpack

#include <PopPack.h>

#pragma comment(lib,"ws2_32.lib")

int main(int argc, char* argv[])

{

WSADATA wsadata={0}

::WSAStartup(MAKEWORD(1,1),&wsadata)

SOCKET sock = socket(AF_INET,SOCK_STREAM,0)

SOCKADDR_IN addr

addr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1")

addr.sin_family = AF_INET

addr.sin_port = htons(1000)

int err = connect(sock,(SOCKADDR*)&addr,sizeof(SOCKADDR))

char resp[1024]={0}

testpack pack={0}

lstrcpyn(pack.msg,"Hello!",sizeof(pack.msg)+1)

pack.msglen = htonl(lstrlen(pack.msg)+4)

pack.cmdid = htonl(111)

int sendlen = sizeof(pack)

while (1)

{

memset(resp,0,sizeof(resp))

err = send(sock,(char*)&pack,sendlen,0)

err = recv(sock,resp,sizeof(resp),0)

testpack* pp = (testpack*)resp

printf("received:[%s]\n",pp->msg)

}

printf("Hello World!\n")

::WSACleanup()

return 0

}

根据你的截图, linux服务器没有配置正确的域名解析服务器

同时,推断你的网络配置,网卡配置不正确。无法正常上网。

如果你是在使用的服务器版本,网络中没有dhcp服务器,需要手动配置网卡地址,子网掩码,和网关,域名服务器地址。


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/247969.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-13
下一篇2023-04-13

发表评论

登录后才能评论

评论列表(0条)

    保存