I'm not on MSN much, so you might be better off emailing me
. Are you sure that it is actually sending and not being received? Use break points to check this. I can't tell you what the problem is without seeing more of your code.
You might be able to work it out. Here is a simple demo showing how to use the 'per client, per operation' UDP mode:
Server
#include <MikeNet.h>
#include <windows.h>
#include <iostream>
using namespace std;
// Operations
const int OP_FLOAT = 0;
const int OP_STRING = 1;
const int OP_INT = 2;
// Entry point
void main()
{
// Setup server
int iReturn = 0;
cout << "DarkNet version: " << mnGetVersion() << "n";
long long int RecvPacket = mnCreatePacket();
long long int SendPacket = mnCreatePacket();
mnSetMemorySize(SendPacket,1024);
mnStart(1,0);
mnSetLocal(0,"127.0.0.1",6565,"127.0.0.1",6565);
mnStartServer(0,50,3,2);
cout << "Server started on TCP port " << mnGetLocalPortTCP(0) << " and UDP port " << mnGetLocalPortUDP(0) << 'n';
// Main loop
bool bRunning = true;
while(bRunning == true)
{
// Use less CPU
Sleep(1);
// New clients
iReturn = mnClientJoined(0);
if(iReturn > 0)
{
cout << "New client joined, ID: " << iReturn << "n";
}
// Leaving clients
iReturn = mnClientLeft(0);
if(iReturn > 0)
{
cout << "Client left, ID: " << iReturn << "n";
}
for(int cl = 1;cl<=mnGetMaxClients(0);cl++)
{
// TCP packets
iReturn = mnRecvTCP(0,RecvPacket,cl);
if(iReturn > 0)
{
cout << "New TCP packet received from client " << iReturn << "n";
}
// UDP packets
for(int op = 0;op<mnGetMaxOperations(0);op++)
{
iReturn = mnRecvUDP(0,RecvPacket,cl,op);
if(iReturn > 0)
{
// Begin formulating packet to send to clients
mnAddInt(SendPacket,cl);
mnAddInt(SendPacket,op);
// Decide what to do depending on operation
switch(op)
{
case(OP_FLOAT):
{
float fl = mnGetFloat(RecvPacket);
cout << "Float received from client " << cl << ": " << fl << 'n';
// Finish formulating packet to send to clients
mnAddFloat(SendPacket,fl);
}
break;
case(OP_STRING):
{
char * str = mnGetStringC(RecvPacket,0,1);
cout << "String received from client " << cl << ": " << str;
// Finish formulating packet to send to clients
mnAddStringC(SendPacket,str,0,true);
// Deallocate memory allocated by mnGetStringC
delete[] str;
}
break;
case(OP_INT):
{
int i = mnGetInt(RecvPacket);
cout << "Integer received from client " << cl << ": " << i << 'n';
// Finish formulating packet to send to clients
mnAddInt(SendPacket,i);
}
break;
default:
cout << "Invalid operationn";
system("PAUSE");
break;
}
// Send packet to all clients (excluding the client we received it from)
mnSendUDPAll(0,SendPacket,0,1,cl);
}
}
}
}
}
Client
#include <MikeNet.h>
#include <windows.h>
#include <iostream>
#include <time.h>
using namespace std;
// Operations
const int OP_FLOAT = 0;
const int OP_STRING = 1;
const int OP_INT = 2;
// Entry point
void main()
{
// Connect to server
int iReturn = 0;
cout << "DarkNet version: " << mnGetVersion() << "n";
long long int RecvPacket = mnCreatePacket();
long long int SendPacket = mnCreatePacket();
mnSetMemorySize(SendPacket,1024);
mnStart(1,0);
iReturn = mnConnect(0,"127.0.0.1",6565,"127.0.0.1",6565,5,true);
switch(iReturn)
{
case(1):
cout << "Connected to servern";
break;
case(0):
cout << "Connection timed outn";
system("PAUSE");
return;
break;
case(-1):
cout << "Error occurred whilst connectingn";
system("PAUSE");
return;
break;
}
// Main loop
unsigned int SendTimer = 0;
unsigned int SendFreq = 300;
while(mnClientConnected(0,0) == 1)
{
// Use less CPU
Sleep(1);
// TCP packets
iReturn = mnRecvTCP(0,RecvPacket,0);
if(iReturn > 0)
{
cout << "New TCP packet receivedn";
}
// UDP packets
for(int cl = 1;cl<=mnGetMaxClients(0);cl++)
{
for(int op = 0;op<mnGetMaxOperations(0);op++)
{
iReturn = mnRecvUDP(0,RecvPacket,cl,op);
if(iReturn > 0)
{
// Decide what to do depending on operation
switch(op)
{
case(OP_FLOAT):
{
float fl = mnGetFloat(RecvPacket);
cout << "Float received from server, that was originally sent by client " << cl << ": " << fl << 'n';
}
break;
case(OP_STRING):
{
char * str = mnGetStringC(RecvPacket,0,1);
cout << "String received from server, that was originally sent by client " << cl << ": " << str;
// Deallocate memory allocated by mnGetStringC
delete[] str;
}
break;
case(OP_INT):
{
int i = mnGetInt(RecvPacket);
cout << "Integer received from server, that was originally sent by client " << cl << ": " << i << 'n';
}
break;
default:
cout << "Invalid operation" << 'n';
system("PAUSE");
break;
}
}
}
}
// Send messages every SendFreq ms
if(clock() - SendTimer > SendFreq)
{
// Operation
int op = rand() % 3; // Random number between 0 and 2
mnAddInt(SendPacket,op);
// Decide what to do depending on operation
switch(op)
{
case(OP_FLOAT):
{
float fl = (rand()*1.0f)+(rand() % 11)*0.1f;
mnAddFloat(SendPacket,fl);
cout << "Float sent to server: " << fl << 'n';
}
break;
case(OP_STRING):
{
time_t time1 = time(NULL);
tm * time2 = localtime(&time1);
char * str = asctime(time2);
mnAddStringC(SendPacket,str,0,true);
cout << "String sent to server: " << str;
}
break;
case(OP_INT):
{
int i = rand();
mnAddInt(SendPacket,i);
cout << "Integer sent to server: " << i << 'n';
}
break;
default:
cout << "Invalid operationn";
system("PAUSE");
break;
}
// Send packet
mnSendUDP(0,SendPacket,0,0,1);
// Update timer
SendTimer = clock();
}
}
}