Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - EiTkoCaT

Pages: 1 2 [3] 4
31
Network / "Endless"-getting-messages problem
« on: May 25, 2011, 11:47:45 pm »
Hey,

so I have this connections I want to get from them always messages and just write them. The thing is that I'm talking about 20 TCP messages per second per client. And there gonna be a lot of clients.

Any way, I have a problem... With my 1 client connected, it's drops me an error in the 3rd message I send. My code is maybe weird, that's right - but that's how I thought. So every time the client sends something like:
3TR 1 name var1 var2\0
and I need the server to split the string every " " so I use string to vector split by boost. Here's my full code:

Code: [Select]
while (CountinewWithPlayer)
{

std::size_t Receiveda = 0;
sf::Socket::Status status;
char MessageLivea[256];
status = (Client.Receive(MessageLivea, sizeof(MessageLivea), Receiveda));
if ( status  == sf::Socket::Disconnected || status  == sf::Socket::Error)
{
cout << "Disconnected" << connectedClients << endl;
CountinewWithPlayer = 0;
} else if ( status  == sf::Socket::Done )
{
cout << MessageLivea << endl;
std::vector<std::string> current_stringLivea;
boost::split(current_stringLivea, MessageLivea, boost::is_any_of(" "));
cout << current_stringLivea[0] << current_stringLivea[1] << current_stringLivea[2] << current_stringLivea[3] << endl;
}
}


My problem:
Quote
Debug Assertion Failed!
 
Program: …
File: c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector
Line: 932
 
Expression: vector subscript out of range
 
For information on how your program can cause an assertion
Failure, see the Visual C++ documentation on asserts.


What to do?
Thanks.

32
System / How should I use threads in here...
« on: December 25, 2010, 02:41:44 pm »
Hey, I have this
Code: [Select]
#include <iostream>
#include <sstream>
#include <string>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include "client/dbclient.h"
#include "Mongo.cpp"
#pragma comment( lib, "mongoclient" )

std::vector<sf::SocketTCP> Users;
std::vector<sf::IPAddress> UsersIP;
sf::SocketTCP Server;
sf::SocketTCP Client;
sf::IPAddress ClientAddress;

int connectedClients = 0;
mongo::DBClientConnection c;
bool server_running;

bool LoginSeccedd;
void serverTCP(void* UserData);
sf::Thread ThreadTCP(&serverTCP);

using namespace std;


void startUserrt(sf::SocketTCP Client, sf::IPAddress ClientAddress) {

/*Users.push_back(Client);
UsersIP.push_back(ClientAddress);

connectedClients++;

for (int i=connectedClients; i<connectedClients;i++)
{
cout << ClientAddress[connectedClients] << endl;
}*/

char Message[256];
std::size_t Received;
if (Client.Receive(Message, sizeof(Message), Received) != sf::Socket::Done)
return;
// Show the message

string stringAll, str3, str4;
stringAll = Message;
size_t found;
size_t total = 0;
string current_string[3];

for (int i=0;i<3;i++)
{
cout << &Message[total] << endl;
found = strlen(&Message[total]);
current_string[i] = &Message[total];
total += found + 1;
}

if (current_string[0] == "7L")
{
// Login
cout << "Login requst" << endl;
mongo::BSONObjBuilder query;
query.append( "email" , current_string[1] ).append( "password", current_string[2] );
mongo::BSONObj res = c.findOne( "test.users" , query.obj() );
string userID = res["email"];
cout << userID << endl;
// session_userEmail = userID;
// session_userID = res["_id"];
if (userID == "EOO")
{
char ToSend2[] = "8L 0 not-found\0";
if (Client.Send(ToSend2, sizeof(ToSend2)) != sf::Socket::Done)
return;
cout << ToSend2 << endl;
}
else
{
char ToSend2[] = "8L 1 1\0";
if (Client.Send(ToSend2, sizeof(ToSend2)) != sf::Socket::Done)
return;
cout << ToSend2 << endl;
LoginSeccedd = true;
}
}
else if (current_string[0] == "7R")
{
// Register
cout << "Register requst" << endl;
   mongo::BSONObjBuilder query;
query.append( "email" , current_string[1] ).append( "password", current_string[2] );
mongo::BSONObj res = c.findOne( "test.users" , query.obj() );
string userID = res["email"];
cout << userID << endl;
if (userID == "EOO")
{
char ToSend2[] = "8R 1\0";
// INSERT USER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!***********************************************************************
if (Client.Send(ToSend2, sizeof(ToSend2)) != sf::Socket::Done)
return;
cout << ToSend2 << endl;
LoginSeccedd = true;
}
else
{
char ToSend2[] = "8R 0 3\0";
if (Client.Send(ToSend2, sizeof(ToSend2)) != sf::Socket::Done)
return;
cout << ToSend2 << endl;
}
}
else
{
cout << "Unknow Request" << endl;
}


if (LoginSeccedd = true)
{
char Message[256];
std::size_t Received;
if (Client.Receive(Message, sizeof(Message), Received) != sf::Socket::Done)
return;
cout << Message << endl;
if (Message == "7MM")
{
// Load Main Menu - send character information
/*string ToSend2 = "8MM";
mongo::BSONObjBuilder query;
query.append( "user_id" , session_userID );

auto_ptr<DBClientCursor> cursor =
c.query("test.characters", query.obj() );
while( cursor->more() ) {
BSONObj p = cursor->next();
cout << p["name"] << endl;
ToSend2 += p["name"];
}
cout << ToSend2 << endl;*/

}
else if (Message == "7CC")
{

}

}
}


void serverTCP(void* UserData) {
while (server_running)
{
// Wait for a connection
   if (Server.Accept(Client, &ClientAddress) != sf::Socket::Done)
return;
cout << "Client connected : " << ClientAddress << std::endl;
startUserrt(Client, ClientAddress);

/*User *current;
current = new User;
current->startUserrt(Client);*/
}
}




void startServer() {
server_running = true;
   if (!Server.Listen(2435))
return;

cout << "Server is listening to port " << 2435 << ", waiting for connections... " << std::endl;
ThreadTCP.Launch();
}

int main()
{
 c.connect("localhost"); //"192.168.58.1");
cout << "connected ok" << endl;
startServer();

    // Wait until the user presses 'enter' key
    std::cout << "Press enter to exit..." << std::endl;
    std::cin.ignore(10000, '\n');
    std::cin.ignore(10000, '\n');

    return EXIT_SUCCESS;

}


This is a server where number of clients logging into it and sending messages. My problem here is not the networking, it's the threads. When a client connect it's not a problem, but it somewhy can't handle more than one client. You see, after a client loged in and the server sends him a message, the client needs to send a message "7MM". But for the check, I'm not sending it. Here's the problem, if client A connects and loged in good-> not sending 7MM and user B also trying to connect, he can't. He have to wait until the function startUserrt of user A will finish itself. So, what do I have to do if I want to make it work for multiple clients? Thanks![/code]

33
Network / Handling Multiple TCP Connections
« on: December 25, 2010, 02:17:24 pm »
Ok, so now it's not a problem to send all the connected users something I want.

But here's my problem now.. The server needs to handle that:
User A sends login request -> sent OK. Now the user is waiting.
User B sends login request -> sent OK. Now the user is waiting.
User C sends login request -> sent OK. Now the user is waiting.
Now user A just sent a load menu request. The server needs to find the menu of user A from the DB, and to send it to user A.
Now user B just sent a load menu request. The server needs to find the menu of user B from the DB, and to send it to user B.
Now user A just choosed the Enter World option from the menu. Then he sends to the server 'enter world'. The server is now searching in the DB where is in the world user A located. Then he sends to user A he's location.
Now user C just sent a load menu request. The server needs to find the menu of user C from the DB, and to send it to user C.
Now user C just choosed the Enter World option from the menu. Then he sends to the server 'enter world'. The server is now searching in the DB where is in the world user C located. Then he sends to user C he's location.
Now user A just jumped in the map. The server searching if there is another user in the same map. There is! User C. He sends to user C 'user A just jumped'


How can I handle that kind of things? It makes me crazy..! How can I recognize in the selector the reads the message what user sent the message and by the user search in the database?

Here's what I tried to do without a selector, but you can find my problem at http://www.sfml-dev.org/forum/viewtopic.php?p=25051#25051. It should just log in a user and wait for a load menu request. I can't handle here number of users trying to connect.


Code: [Select]
#include <iostream>
#include <sstream>
#include <string>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include "client/dbclient.h"
#include "Mongo.cpp"
#pragma comment( lib, "mongoclient" )

std::vector<sf::SocketTCP> Users;
std::vector<sf::IPAddress> UsersIP;
   sf::SocketTCP Server;
   sf::SocketTCP Client;
   sf::IPAddress ClientAddress;

int connectedClients = 0;
mongo::DBClientConnection c;
bool server_running;

bool LoginSeccedd;
void serverTCP(void* UserData);
sf::Thread ThreadTCP(&serverTCP);

using namespace std;


void startUserrt(sf::SocketTCP Client, sf::IPAddress ClientAddress) {

   /*Users.push_back(Client);
   UsersIP.push_back(ClientAddress);

   connectedClients++;
   
   for (int i=connectedClients; i<connectedClients;i++)
   {
      cout << ClientAddress[connectedClients] << endl;
   }*/

   char Message[256];
   std::size_t Received;
   if (Client.Receive(Message, sizeof(Message), Received) != sf::Socket::Done)
      return;
   // Show the message
   
   string stringAll, str3, str4;
   stringAll = Message;
   size_t found;
   size_t total = 0;
   string current_string[3];

   for (int i=0;i<3;i++)
   {
      cout << &Message[total] << endl;
      found = strlen(&Message[total]);
      current_string[i] = &Message[total];
      total += found + 1;
   }

   if (current_string[0] == "7L")
   {
      // Login
      cout << "Login requst" << endl;
      mongo::BSONObjBuilder query;
      query.append( "email" , current_string[1] ).append( "password", current_string[2] );
      mongo::BSONObj res = c.findOne( "test.users" , query.obj() );
      string userID = res["email"];
      cout << userID << endl;
   //   session_userEmail = userID;
   //   session_userID = res["_id"];
      if (userID == "EOO")
      {
         char ToSend2[] = "8L 0 not-found\0";
         if (Client.Send(ToSend2, sizeof(ToSend2)) != sf::Socket::Done)
            return;
         cout << ToSend2 << endl;
      }
      else
      {
         char ToSend2[] = "8L 1 1\0";
         if (Client.Send(ToSend2, sizeof(ToSend2)) != sf::Socket::Done)
            return;
         cout << ToSend2 << endl;
         LoginSeccedd = true;
      }
   }
   else if (current_string[0] == "7R")
   {
      // Register
      cout << "Register requst" << endl;
       mongo::BSONObjBuilder query;
      query.append( "email" , current_string[1] ).append( "password", current_string[2] );
      mongo::BSONObj res = c.findOne( "test.users" , query.obj() );
      string userID = res["email"];
      cout << userID << endl;
      if (userID == "EOO")
      {
         char ToSend2[] = "8R 1\0";
         // INSERT USER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!***********************************************************************
         if (Client.Send(ToSend2, sizeof(ToSend2)) != sf::Socket::Done)
            return;
         cout << ToSend2 << endl;
         LoginSeccedd = true;
      }
      else
      {
         char ToSend2[] = "8R 0 3\0";
         if (Client.Send(ToSend2, sizeof(ToSend2)) != sf::Socket::Done)
            return;
         cout << ToSend2 << endl;
      }
   }
   else
   {
      cout << "Unknow Request" << endl;
   }


   if (LoginSeccedd = true)
   {
      char Message[256];
      std::size_t Received;
      if (Client.Receive(Message, sizeof(Message), Received) != sf::Socket::Done)
         return;
      cout << Message << endl;
      if (Message == "7MM")
      {
         // Load Main Menu - send character information
         /*string ToSend2 = "8MM";
         mongo::BSONObjBuilder query;
         query.append( "user_id" , session_userID );

         auto_ptr<DBClientCursor> cursor =
         c.query("test.characters", query.obj() );
         while( cursor->more() ) {
            BSONObj p = cursor->next();
            cout << p["name"] << endl;
            ToSend2 += p["name"];
         }
         cout << ToSend2 << endl;*/
           
      }
      else if (Message == "7CC")
      {

      }
         
   }
}


void serverTCP(void* UserData) {
   while (server_running)
   {
      // Wait for a connection
       if (Server.Accept(Client, &ClientAddress) != sf::Socket::Done)
         return;
      cout << "Client connected : " << ClientAddress << std::endl;
      startUserrt(Client, ClientAddress);

            /*User *current;
         current = new User;
      current->startUserrt(Client);*/
   }
}




void startServer() {
   server_running = true;
       if (!Server.Listen(2435))
      return;
   
   cout << "Server is listening to port " << 2435 << ", waiting for connections... " << std::endl;
   ThreadTCP.Launch();
}

int main()
{
     c.connect("localhost"); //"192.168.58.1");
    cout << "connected ok" << endl;
startServer();

    // Wait until the user presses 'enter' key
    std::cout << "Press enter to exit..." << std::endl;
    std::cin.ignore(10000, '\n');
    std::cin.ignore(10000, '\n');

    return EXIT_SUCCESS;

}

34
Network / Handling Multiple TCP Connections
« on: December 21, 2010, 08:19:55 pm »
I don't undertand an important thing here.
Let's say I currently have 3 clients (could be 10K either..). Client A just connected to the server and send a log in request as a message with username and password. Now user B and C also connected and loged in. Surely they also got a OK message. Now, user B wants to change he's status from "Happy" to "Sad", so he sends a message to the server. So now I'm gonna need to send to clients A and C that client B's status changed. How can I send them a thing like that? How can I identify a client who is sending a message? The message that client B sends to the server should be, for example:
status sad
and then the server should send him back:
stats changed
and the server needs to send to user A and C:
user B status change sad

Just an example. So how can I do that? Thanks!

35
Network / Handling Multiple TCP Connections
« on: December 19, 2010, 11:45:50 pm »
Oh, now I get it...
Well, you really helped me! Thank you very much!

36
Network / Handling Multiple TCP Connections
« on: December 19, 2010, 11:40:50 pm »
That's exactly the problem, I need to know from what IP I'm getting every message. How can I test which IP sent me the message and skep him when I don't know any message's sender IP?

37
Network / Handling Multiple TCP Connections
« on: December 19, 2010, 11:16:39 pm »
That's it!! Client array! How can I do that? I'm pretty new in C++, sorry for that, but yeah :X
I never worked with C++ and the client isn't written in C++, but I found SFML to be the best network library so I'm using it.

Also in step 2, how can I access the sendes's IP? I mean, all I see here, in that selector is (in the SFML sample):
                sf::Packet Packet;
                if (Socket.Receive(Packet) == sf::Socket::Done)
                {
                    // Extract the message and display it
                    std::string Message;
                    Packet >> Message;
                    std::cout << "A client says : \"" << Message << "\"" << std::endl;
                }

38
Network / Handling Multiple TCP Connections
« on: December 19, 2010, 11:09:30 pm »
Yeah, because I can go on from there. It won't be like that in the game, but after I'll see a working code for broadcast the message to everyone but the sender, I'll know how to build what I want exactly. So yes :D

Thanks..!

39
Network / Handling Multiple TCP Connections
« on: December 19, 2010, 10:50:08 pm »
Oh, thanks! I didn't knew about network selector. But how can I do with that what I wanted in first place (my first message)?

Thanks!

40
Network / Handling Multiple TCP Connections
« on: December 19, 2010, 09:22:45 pm »
It's a server game. As I said, lot of clients needs to get connected.
When I need to do something like what I need, the user is always opens the first chat. But I heard that I can't connect multiple chats and keep them alive and also connect with each other (eg. send the data I got from client 1 to 2, 3, 4, 5), and I have to always close the chats, store the IP loged in into a DB (non-sql, of course..) and when I need to send a message to one of the clients I must start a new chat from the server to the client.

1. Is that correct? There isn't a way keeping alive lot of TCP chats the same time and connect between them?
2. If it is, I think I have a problem here. If the server needs to open the chat, then the client needs to listen to it always. But when the client connected to a wireless and there's a fiewwall, I can't connect him, can I? How do you solve that problem?

41
Network / Handling Multiple TCP Connections
« on: December 18, 2010, 11:51:27 pm »
Hey,

I have a problem handling multiple TCP connections on a C++ app that uses SFML library to send and read TCP messages.

Let's say I need to have 5 TCP connections to the server once (can be also 10K, just for example..). When client 1 sends a message, the server process it and then should send a message to clients 2-5, let's say in that case that he should send the same message.
How can I do that?

Thanks!

42
Network / Wired Problem
« on: November 20, 2010, 09:07:29 pm »
You are right..

43
Network / Wired Problem
« on: November 20, 2010, 08:33:30 pm »
Hello,

I'm using SFML to get messages from clients. I'm sending a msg, for exemple: "Schogini Systems", but somewhy, I get in the server this "Schogini Systems╠╠╠╠▌óea└÷^♦]ז╖".

When I'm sending MSGS from a SFML client it's all OK.

WTF?

44
Network / Using SSL
« on: November 11, 2010, 09:50:08 pm »
Hey,

I'd like to add a SSL secure to the connections. Is it possible? If yes, how to? I'm using UDP and TCP, don't thing there needs to be other detail :)

Thanks!

45
Network / UDP Server - Handling multiple connections
« on: September 16, 2010, 09:36:18 pm »
Quote from: "purkskis"
i was asking something similar few topicks lower
you dont need selector if you are using only one socket

and here is my attempt to creat multiple client <-> server application with UDP, but it lags :/


Thanks for the answer, but I still can't undertsnad how to do that!

Pages: 1 2 [3] 4
anything