Skip to content

Commit 9f0971c

Browse files
author
kbengine
committed
git-svn-id: https://kbengine.svn.sourceforge.net/svnroot/kbengine@206 d26bdfbe-e24b-4f15-971f-8e0596e1bc08
1 parent bc0f586 commit 9f0971c

13 files changed

Lines changed: 220 additions & 33 deletions

File tree

‎kbe/src/examples/testnetwork/main.cpp‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,28 @@ MyPacketReceiver* packetReceiver;
183183

184184
void init_network(void)
185185
{
186+
mysocket.close();
187+
mysocket.socket(SOCK_DGRAM);
188+
mysocket.setbroadcast(true);
189+
if (!mysocket.good())
190+
{
191+
ERROR_MSG("NetworkInterface::recreateListeningSocket: couldn't create a socket\n");
192+
return;
193+
}
194+
195+
while(1)
196+
{
197+
TCPPacket packet;
198+
186199
Bundle bundle;
187200
bundle.newMessage(CellAppInterface::test);
188201
ENTITY_ID eid = 1;
189202
bundle << eid;
190203
char xxa[12]={"kebiao12345"};
191204
std::string sss = xxa;
192205
bundle << sss;
193-
194-
bundle.finish();
195-
196-
MessageID msgID;
197-
bundle >> msgID;
198-
199-
MessageLength len;
200-
bundle >> len;
201-
bundle >> sss;
206+
bundle.sendto(mysocket, htons(KBE_MACHINE_BRAODCAST_PORT), Mercury::BROADCAST);
207+
}
202208

203209
while(1)
204210
{

‎kbe/src/lib/cstdkbe/cstdkbe.hpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ const char COMPONENT_NAME[][12] = {
7070
};
7171

7272
/** 一个cell边界能够看到另一个cell边界的最大范围 */
73-
#define CELL_BORDER_WIDTH 500
73+
#define CELL_BORDER_WIDTH 500
7474

7575
/** 一个空间的一个chunk大小 */
76-
#define SPACE_CHUNK_SIZE 100
76+
#define SPACE_CHUNK_SIZE 100
7777

7878
/** kbe machine端口 */
79-
#define KBE_MACHINE_BRAODCAST_PORT 20086
80-
#define KBE_MACHINE_TCP_PORT 20088
79+
#define KBE_MACHINE_BRAODCAST_PORT 20086
80+
#define KBE_PORT_BROADCAST_DISCOVERY 20087
81+
#define KBE_MACHINE_TCP_PORT 20088
8182

8283
}
8384
#endif // __CSTDKBE__

‎kbe/src/lib/network/bundle.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ void Bundle::send(EndPoint& ep)
117117
onSendComplete();
118118
}
119119

120+
//-------------------------------------------------------------------------------------
121+
void Bundle::sendto(EndPoint& ep, u_int16_t networkPort, u_int32_t networkAddr)
122+
{
123+
finish();
124+
125+
Packets::iterator iter = packets_.begin();
126+
for (; iter != packets_.end(); iter++)
127+
{
128+
Packet* pPacket = (*iter);
129+
ep.sendto(pPacket->data(), pPacket->totalSize(), networkPort, networkAddr);
130+
delete pPacket;
131+
}
132+
133+
onSendComplete();
134+
}
135+
120136
//-------------------------------------------------------------------------------------
121137
void Bundle::onSendComplete()
122138
{

‎kbe/src/lib/network/bundle.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Bundle
5353

5454
void send(NetworkInterface & networkInterface, Channel * pChannel);
5555
void send(EndPoint& ep);
56+
void sendto(EndPoint& ep, u_int16_t networkPort, u_int32_t networkAddr = BROADCAST);
5657
void onSendComplete();
5758

5859
void clear();

‎kbe/src/lib/network/common.hpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ same license as the rest of the engine.
2222
namespace KBEngine {
2323
namespace Mercury
2424
{
25+
const uint32 BROADCAST = 0xFFFFFFFF;
26+
const uint32 LOCALHOST = 0x0100007F;
2527

2628
typedef uint8 MessageID;
2729
typedef uint16 MessageLength; // ×î´ó65535

‎kbe/src/lib/network/endpoint.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class EndPoint
8282

8383
bool getClosedPort(Mercury::Address & closedPort);
8484

85-
int sendto(void * gramData, int gramSize, u_int16_t networkPort, u_int32_t networkAddr = INADDR_BROADCAST);
85+
int sendto(void * gramData, int gramSize, u_int16_t networkPort, u_int32_t networkAddr = BROADCAST);
8686
INLINE int sendto(void * gramData, int gramSize, struct sockaddr_in & sin);
8787
INLINE int recvfrom(void * gramData, int gramSize, u_int16_t * networkPort, u_int32_t * networkAddr);
8888
INLINE int recvfrom(void * gramData, int gramSize, struct sockaddr_in & sin);

‎kbe/src/lib/network/event_dispatcher.hpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class EventDispatcher
3434
int processOnce(bool shouldIdle = false);
3535
void processUntilBreak();
3636

37+
bool isBreakProcessing()const { return breakProcessing_; }
38+
3739
void breakProcessing(bool breakState = true);
3840
bool processingBroken()const;
3941

‎kbe/src/lib/network/udp_packet.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ int UDPPacket::recvFromEndPoint(EndPoint & ep, Address* pAddr)
3030
(u_int16_t*)&pAddr->port, (u_int32_t*)&pAddr->ip);
3131

3232
wpos(len);
33+
printf("*******************************%d\n", len);
3334
return len;
3435
}
3536

‎kbe/src/lib/network/udp_packet_receiver.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ UDPPacketReceiver::~UDPPacketReceiver()
3131
//-------------------------------------------------------------------------------------
3232
bool UDPPacketReceiver::processSocket(bool expectingPacket)
3333
{
34-
Channel* pChannel = networkInterface_.findChannel(endpoint_.addr());
35-
KBE_ASSERT(pChannel != NULL);
34+
// Channel* pChannel = networkInterface_.findChannel(endpoint_.addr());
35+
// KBE_ASSERT(pChannel != NULL);
36+
37+
// Packet* pReceiveWindow = pChannel->receiveWindow();
38+
Packet* pReceiveWindow = new UDPPacket;
3639

37-
Packet* pReceiveWindow = pChannel->receiveWindow();
38-
3940
Address srcAddr;
4041
int len = pReceiveWindow->recvFromEndPoint(endpoint_, &srcAddr);
4142

‎kbe/src/server/cellapp/cellapp.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ void CellApp::handleGameTick()
103103
//-------------------------------------------------------------------------------------
104104
bool CellApp::initializeBegin()
105105
{
106-
if(thread::ThreadPool::getSingletonPtr() && !thread::ThreadPool::getSingleton().isInitialize() )
107-
thread::ThreadPool::getSingleton().createThreadPool( 16, 16, 256 );
106+
if(thread::ThreadPool::getSingletonPtr() &&
107+
!thread::ThreadPool::getSingleton().isInitialize())
108+
thread::ThreadPool::getSingleton().createThreadPool(16, 16, 256);
108109

109110
return true;
110111
}

0 commit comments

Comments
 (0)