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

Author Topic: Network Chat Example - strange issue  (Read 2775 times)

0 Members and 1 Guest are viewing this topic.

lafoniz

  • Newbie
  • *
  • Posts: 19
    • View Profile
Network Chat Example - strange issue
« on: December 15, 2014, 04:00:41 pm »
Hello folks, I wanted to test network library from SFML, so I thought it would the best to use some kind of example. I have chosen code from this wiki site: https://github.com/SFML/SFML/wiki/Source:-Network-Chat-Example
It was working perfectly for my desktop computer and I didn't have any problems with it. After that I have taken code from the same website and tried to run the app on my laptop, but a very strange issue appeared.
Almost instantaneously I had 40% CPU usage, just from it and nothing showed up.

I did some test which showed that is it some kind of problem with compiling or linking, because I used this bugged exe app  on my desktop computer and it still didn't work.

The huge problem is:
1. I'm using the same IDE on both computers, it's Code::Blocks with MinGW compilator.
2. Computers have the same SFML files and the same operating systems.
3. Compiling process on my laptop doesn't return any errors or warnings.

Link to this bugged application: http://www.speedyshare.com/Ftye2/Network-app.rar

Have anybody seen something like this?

PS. I know my description may be a little chaotic, if you need anything more, please just tell me.

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Network Chat Example - strange issue
« Reply #1 on: December 15, 2014, 04:22:55 pm »
Can you please post the code you are using (Complete and minimal) as well as the specs for your laptop?

lafoniz

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Network Chat Example - strange issue
« Reply #2 on: December 15, 2014, 04:55:26 pm »
Can you please post the code you are using (Complete and minimal) as well as the specs for your laptop?

Code of the program is the same as on the wiki.
Information about laptop:
ASUS X53S with NVIDIA GeForce GT 540M, Intel Core i5-2430M 2,4 GHz clock, operating system is Windows 7 Ultimate with SP1

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Network Chat Example - strange issue
« Reply #3 on: December 15, 2014, 05:38:16 pm »
The code on the wiki is questionable to say the least - note the wiki contains user contributions and are usually not written by anyone of the SFML Team - but it makes sense that your application consumes a lot of CPU time, because in the DoStuff function, which gets called in a separate thread, there's a while loop that iterates as fast as possible, meaning as fast as your CPU can go, meaning high CPU usage.

One of the main issue in this example is that the TCP socket always sends messages, even if it's not needed, it'll be sending and receiving the last message as fast as possible.
And then there's the whole global variables stuff etc.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

lafoniz

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Network Chat Example - strange issue
« Reply #4 on: December 15, 2014, 06:02:06 pm »
The code on the wiki is questionable to say the least - note the wiki contains user contributions and are usually not written by anyone of the SFML Team - but it makes sense that your application consumes a lot of CPU time, because in the DoStuff function, which gets called in a separate thread, there's a while loop that iterates as fast as possible, meaning as fast as your CPU can go, meaning high CPU usage.

One of the main issue in this example is that the TCP socket always sends messages, even if it's not needed, it'll be sending and receiving the last message as fast as possible.
And then there's the whole global variables stuff etc.

Well, i have forgotten that non-staff code may be a little bad to learn from :) Thanks for help, all of you.