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 - mcphee.d

Pages: [1]
1
Network / UDP are delayed. Linux settings?
« on: September 11, 2011, 04:48:47 am »
... are you the same person who posted this:

http://askubuntu.com/questions/60870/udp-tuning-ubuntu-how-to

?

There are some answers there that look helpful -- beyond those, I would think that this forum isn't really the place to ask things like this, as it's not really SFML related.

2
Network / sf::Packet.Clear() heap corruption?
« on: September 05, 2011, 07:16:56 pm »
So we changed the
Code: [Select]
std::string got
to a
Code: [Select]
char got[128]
and now it works fine.

I'm not sure why std::string would crash it in such a way, but apparently it did!

3
Network / sf::Packet.Clear() heap corruption?
« on: August 29, 2011, 06:47:44 pm »
I see! Thanks for the explanation.

Okay, well - I changed it to non-clr (and took 'public' out of 'public class', etc), but it still produces the same error.

4
Network / sf::Packet.Clear() heap corruption?
« on: August 29, 2011, 03:56:15 pm »
There isn't a reason -- I didn't even know that was a ... thing! Hehe. When setting up the project, I guess I must have chose it.

I'll try turning CLR off, but what's the difference between this and "native C++"? You're right -- as far as I can tell I've just been writing C++. I didn't know I wasn't ... really writing C++? I'm confused lol.

5
Network / sf::Packet.Clear() heap corruption?
« on: August 29, 2011, 01:55:12 pm »
I haven't tried that -- what option are you referring to?

6
Network / sf::Packet.Clear() heap corruption?
« on: August 29, 2011, 02:47:48 am »
Hello! Sorry for the delay.

mv_server.h:
Code: [Select]

#include "stdafx.h"

public class mv_server {
public:
mv_server::mv_server();
mv_server::~mv_server();

private:
sf::TcpListener listener;
void listen_loop();
sf::Thread* Thread;
std::vector<sf::TcpSocket*> clients;
sf::SocketSelector selector;
};


mv_server.cpp:
Code: [Select]


#include "stdafx.h"

mv_server::mv_server() {
//initialize connection tcp listener
std::cout << "Initializing tcp listener ..." << std::endl;
listener.Listen(55001);
//boost::thread worker_thread(boost::bind(&mv_server::listen_loop,this));
selector.Add(listener);
Thread = new sf::Thread(&mv_server::listen_loop, this);
Thread->Launch();
}

mv_server::~mv_server() {

}

void mv_server::listen_loop() {
while(1) {
if(selector.Wait()) {
if(selector.IsReady(listener)) {
sf::TcpSocket* client = new sf::TcpSocket();
if(listener.Accept(*client) == sf::Socket::Done) {
clients.push_back(client);
selector.Add(*client);
}
}
else {
for(std::vector<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); it++) {
sf::TcpSocket& client = **it;
if(selector.IsReady(client)) {
sf::Packet recv_packet;
sf::Packet send_packet;
if(client.Receive(recv_packet) == sf::Socket::Done) {
std::string got;
recv_packet >> got;
std::cout << "The client said: " << got << std::endl;
//packet.Clear();
send_packet << "Got yo message yo";
client.Send(send_packet);
}
}
}
}
}
}
}


mv_main.cpp:
Code: [Select]

int main(array<System::String ^> ^args)
{
sf::TcpSocket connection_dude;
bool connected_to_dude = false;
sf::RenderWindow menu_win(sf::VideoMode(400, 400, 32), "MV Menu");
//fork off a server
mv_server *listener = new mv_server();
//connect to it for a one-off test
//NOTE: I used my WAN ip here; insert your own or localhost or something
int status = connection_dude.Connect("xx.xxx.xxx.xxx", 55001);
connected_to_dude = true;

while(menu_win.IsOpened()) {
sf::Event e;
while(menu_win.PollEvent(e)) {
//close
if(e.Type == sf::Event::Closed) { menu_win.Close(); }
if(e.Type == sf::Event::KeyPressed) {
if(e.Key.Code == sf::Keyboard::A) {
//send a message to our server
if(connected_to_dude) {
sf::Packet p;
p << "We pressed A";
int status = connection_dude.Send(p);
p.Clear();
connection_dude.Receive(p);
std::string got;
p >> got;
std::cout << "Server says " << got << std::endl;
std::cout << "Sent status: " << status << std::endl;
p.Clear();
} else {
std::cout << "connect first!" << std::endl;
}
}
}
           }
}
} //end main


stdafx.h:
Code: [Select]

#pragma once

#include <iostream>
#include <stdlib.h>

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

#include "mv_server.h"


Some details, if they matter --
I'm using VS2008, the latest (well, as of a couple weeks ago) SFML build from github, and my OS is Windows 7 64-bit. I'm building this in Debug configuration.

Thanks!

7
Network / sf::Packet.Clear() heap corruption?
« on: August 27, 2011, 06:05:16 am »
Hello,

I have this simple server code, taken pretty much directly from the selector tutorial:
Code: [Select]


void mv_server::listen_loop() {
while(1) {
if(selector.Wait()) {
if(selector.IsReady(listener)) {
sf::TcpSocket* client = new sf::TcpSocket();
if(listener.Accept(*client) == sf::Socket::Done) {
clients.push_back(client);
selector.Add(*client);
}
}
else {
for(std::vector<sf::TcpSocket*>::iterator it = clients.begin(); it != clients.end(); it++) {
sf::TcpSocket& client = **it;
if(selector.IsReady(client)) {
sf::Packet recv_packet;
sf::Packet send_packet;
if(client.Receive(recv_packet) == sf::Socket::Done) {
std::string got;
recv_packet >> got;
std::cout << "The client said: " << got << std::endl;
//packet.Clear();
send_packet << "Got yo message yo";
client.Send(send_packet);
}
}
}
}
}
}
}


This function is in an sf::thread which is called earlier.

Then, this simple client code:

Code: [Select]

if(e.Type == sf::Event::KeyPressed) {
if(e.Key.Code == sf::Keyboard::A) {
//send a message to our server
if(connected_to_dude) {
sf::Packet p;
p << "We pressed A";
int status = connection_dude.Send(p);
p.Clear();
connection_dude.Receive(p);
std::string got;
p >> got;
std::cout << "Server says " << got << std::endl;
std::cout << "Sent status: " << status << std::endl;
p.Clear();
} else {
std::cout << "connect first!" << std::endl;
}
}
}


Running this and triggering that event crashes the program, complaining of a heap corruption. If I remove that "p.Clear()" there, it doesn't crash. However, I now have to pop two items off the packet to get my server's response, right? So I do

Code: [Select]

std::string got;
std::string got2;
p >> got >> got2;


...and it crashes with the same heap corruption.

Am I missing something? I left out various instantiations to save on space; if you need any more info let me know!

Pages: [1]