|
|

楼主 |
发表于 2004-12-14 20:38:00
|
显示全部楼层
Re:今天去上海某游戏公司的面试经历
顺便问下现在论坛有没有研究wow,模拟器的同好,我有个计划是开发一个开源的服务器引擎,用wow来验证该引擎的可行性,初步估计服务端引擎至少需要三块内容,网络库,数据库接口及脚本处理系统,我正在处理网络部分,不只有没有人愿意合作?下面是采用我的库完成的一个简单的服务端和客户端程序示例
server:
#include <iostream>
#include <stdlib.h>
#include "net/ipv4.h"
#include "net/protocol.h"
#include "net/address.h"
#include "net/socket.h"
#include "net/communicator.h"
#include "net/connector.h"
#include "net/acceptor.h"
using namespace net;
int main(int argc, char *argv[])
{
typedef Acceptor< TCP<INET4> > Acceptor;
typedef Acceptor::Address Address;
typedef Acceptor::comm_t comm_t;
Address addr("127.0.0.1", 7994);
std::cout << addr.ip() << ":" << addr.port() << std::endl;
comm_t comm;
Acceptor acceptor;
std::cout << "open:" << acceptor.open(addr, 1) << std::endl;
std::cout << "accept:" << acceptor.accept(comm, addr) << std::endl;
std::cout << "from:" << addr.ip() << ":" << addr.port() << std::endl;
char buf[128];
int len = comm.recv(buf, sizeof(buf));
std::cout << len << std::endl;
buf[len] = '\0';
std::cout << buf << std::endl;
comm.send("hi, client\n", strlen("hi, client\n"));
system(" AUSE");
return 0;
}
client:
#include <iostream>
#include <stdlib.h>
#include "net/config.h"
#include "net/ipv4.h"
#include "net/protocol.h"
#include "net/address.h"
#include "net/socket.h"
#include "net/communicator.h"
#include "net/connector.h"
#include "net/acceptor.h"
using namespace net;
int main(int argc, char *argv[])
{
typedef Connector<TCP<INET4> > Connector;
typedef Connector::comm_t comm_t;
typedef Connector::Address Address;
Connector connector;
comm_t comm;
Address address("127.0.0.1", 7994);
std::cout << connector.connect(comm, address) << std::endl;
comm.send("hi, server\n", strlen("hi, server\n"));
char buf[128];
//option::non_blocking non_block(0);
int len = comm.recv(buf, sizeof(buf));
buf[len] = '\0';
std::cout << buf << std::endl;
std::cout << "from:" << address.ip() << ":" << address.port() << std::endl;
system("PAUSE");
return 0;
}
|
|