rendered paste bodyusing namespace std;
#include <iostream>
#include <direct.h>
#include "socket.h"
#include <process.h>
#include <string>
//SocketClient s("irc.quakenet.org",6667);
SocketServer in(7533,5);
const TABLE_WIDTH = 1024;
const TABLE_HEIGHT = 1024;
class Ship {
int x, y;
float speed_x, speed_y;
public:
void set_speed (float,float);
void resolve_speed ();
};
void Ship::set_values (int a, int b) {
speed_x = a;
speed_y = b;
}
void Ship::resolve_speed () {
x += speed_x;
y += speed_y;
}
unsigned __stdcall Answer(void* a) {
Socket* s = (Socket*) a;
while (1) {
std::string r = s->ReceiveLine();
/******************
Stuff to do on action here.
******************/
if (r.empty()) break;
/* r - message received.
s - server */
int i;
std::string rx = "";
for(i = 0; i < r.length()-2; i++)
{
rx = rx + r[i];
// cout << rx << endl;
}
cout << "Message received: " << rx << endl;
// cout << rx << "-" << "dir";
if (rx =="dir")
{
}
}
delete s;
return 0;
}
int InitWorld() {
}
unsigned __stdcall Think(void* a) {
Socket* s = (Socket*) a;
while(1) {
cout << "test1";
}
delete s;
return 0;
}
/*****************************************/
int main()
{
cout << "Init program." << endl;
cout << "Listening on port 7533 as a server." << endl;
InitWorld();
unsigned ret2;
_beginthreadex(0,0,Think,(void*) s,0,&ret2);
while (1) {
Socket* s=in.Accept();
/******************
Stuff to do on connection here.
******************/
unsigned ret;
_beginthreadex(0,0,Answer,(void*) s,0,&ret);
}
return 0;
}