• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:24
CET 07:24
KST 15:24
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL22] Finals Preview: Sweet Victory!9[ASL22] Ro4 Preview: Mirror Mirror6[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11[ASL22] Ro16 Preview: Holy Diver5
Community News
Evil Geniuses - shutting down14ISSL (IntoTheTV x SOOP SC2 League): Premier5Weekly Cups (October 12-18): 5.0.17 era begins1[$1250] International ShieldBattery League75Weekly Cups (October 5-11): Farewell to 5.0.167
StarCraft 2
General
How do you feel about the mass reverts in the 5.0.17 PTR? REPORT: StarCraft 2: Remastered In Development Team Liquid Map Contest #22: Results and Winners No more SC2 streamers on team liquid? Evil Geniuses - shutting down
Tourneys
ScienceCraft (October 24-25) - Live Event Sparkling Tuna Cup - Weekly Open Tournament RSL goes to London! 2026 Offline Finals Nov 21-22 ISSL (IntoTheTV x SOOP SC2 League): Premier WORTEX Challenger Series — Open SC2 LAN in Budapes
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
[G] How to playtest arcade maps [A] Nemrods 1/4 players [M] (2) Sweltering Sands
External Content
Mutation # 549 Endless Sparkles The PondCast: SC2 News & Results Mutation # 548 Shining Bright Mutation # 547 Temple Of Terror
Brood War
General
Recent recommended BW games Oceanic Brood War - Join and chat! Bot on ladder BW General Discussion Sagi.gg Launcher Released
Tourneys
[Megathread] Daily Proleagues [$1250] International ShieldBattery League [ASL22] Grand Finals [BSL23] RO24 Group C
Strategy
Cliff Jump Revisited (1 in a 1000 strategy) 50,000-Word Terran Builds Memo 2026-10-22 Simple Questions, Simple Answers
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Mobile Legends: Bang Bang Armies of Exigo - YesYes? General RTS Discussion Thread
Dota 2
Dota 2 Champions League Season 3 Begins April 25!
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine US Politics Mega-thread European Politico-economics QA Mega-thread Russo-Ukrainian War Thread
Fan Clubs
Reynor Fan Club The Flash Fan Club Serral Fan Club
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Innovate or Game Over?
TrAiDoS
ShieldBattery on Mac
Kraekkling
[ASL22] Ro4 Day1 Ticket Giv…
bITt.mAN
Can Bots Beat Pros?? Starcr…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7121 users

The Big Programming Thread - Page 321

Forum Index > General Forum
Post a Reply
Prev 1 319 320 321 322 323 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
MaGariShun
Profile Joined May 2010
Austria305 Posts
Last Edited: 2013-07-07 15:20:19
July 07 2013 15:19 GMT
#6401
On July 08 2013 00:11 mustache wrote:
C++ TCP socket programming question:

I've written a small chat program where the client can send a message to the server.
i'm using the following piece of code to establish the connection


sockaddr_in connectionInfo;
connectionInfo.sin_addr.s_addr = inet_addr("127.0.0.1");
connectionInfo.sin_family = AF_INET;
connectionInfo.sin_port = htons(54345);
int connectionInfoLen = sizeof(connectionInfo);

connect(clientSocket, (struct sockaddr*)&connectionInfo,connectionInfoLen);


this works perfectly fine when im using my own pc as both client and server, the IP i enter on both sides is simply 127.0.0.1

But what IP do I use if I want to connect to my friends PC if we both have a router in between? only the router's IPs are unique, so wouldnt i have to specify both the unique router IP as well as the internal IP of the PC?

I searched google but I couldnt find anything related to this, possibly because im not searching for the right keywords.

Your friend has to change his router settings so that connections to the port (54345 I presume) get redirected to his actual PC. Then you only have to know his router address
mustache
Profile Joined April 2010
Switzerland309 Posts
Last Edited: 2013-07-07 15:26:59
July 07 2013 15:25 GMT
#6402
On July 08 2013 00:19 MaGariShun wrote:
Show nested quote +
On July 08 2013 00:11 mustache wrote:
C++ TCP socket programming question:

I've written a small chat program where the client can send a message to the server.
i'm using the following piece of code to establish the connection


sockaddr_in connectionInfo;
connectionInfo.sin_addr.s_addr = inet_addr("127.0.0.1");
connectionInfo.sin_family = AF_INET;
connectionInfo.sin_port = htons(54345);
int connectionInfoLen = sizeof(connectionInfo);

connect(clientSocket, (struct sockaddr*)&connectionInfo,connectionInfoLen);


this works perfectly fine when im using my own pc as both client and server, the IP i enter on both sides is simply 127.0.0.1

But what IP do I use if I want to connect to my friends PC if we both have a router in between? only the router's IPs are unique, so wouldnt i have to specify both the unique router IP as well as the internal IP of the PC?

I searched google but I couldnt find anything related to this, possibly because im not searching for the right keywords.

Your friend has to change his router settings so that connections to the port (54345 I presume) get redirected to his actual PC. Then you only have to know his router address


but which pc port would the router connect to? And how would this work if he has a router connected to a router connected to a wireless router? or can all this be set in the router settings?

also how would this normally work? its not like you have to reconfigure your router based on what program you're running...
MaGariShun
Profile Joined May 2010
Austria305 Posts
July 07 2013 15:45 GMT
#6403
On July 08 2013 00:25 mustache wrote:
Show nested quote +
On July 08 2013 00:19 MaGariShun wrote:
On July 08 2013 00:11 mustache wrote:
C++ TCP socket programming question:

I've written a small chat program where the client can send a message to the server.
i'm using the following piece of code to establish the connection


sockaddr_in connectionInfo;
connectionInfo.sin_addr.s_addr = inet_addr("127.0.0.1");
connectionInfo.sin_family = AF_INET;
connectionInfo.sin_port = htons(54345);
int connectionInfoLen = sizeof(connectionInfo);

connect(clientSocket, (struct sockaddr*)&connectionInfo,connectionInfoLen);


this works perfectly fine when im using my own pc as both client and server, the IP i enter on both sides is simply 127.0.0.1

But what IP do I use if I want to connect to my friends PC if we both have a router in between? only the router's IPs are unique, so wouldnt i have to specify both the unique router IP as well as the internal IP of the PC?

I searched google but I couldnt find anything related to this, possibly because im not searching for the right keywords.

Your friend has to change his router settings so that connections to the port (54345 I presume) get redirected to his actual PC. Then you only have to know his router address


but which pc port would the router connect to? And how would this work if he has a router connected to a router connected to a wireless router? or can all this be set in the router settings?

also how would this normally work? its not like you have to reconfigure your router based on what program you're running...

Basically, to get around NAT (Network Address Translation) you always have to configure to router to do it. There are possibilities to do that remotely from your side by talking to the router (keyword: NAT traversal), but I have no experience with that so I can't tell you exactly how.

Multiple routers should not be a problem. If he is using the routers as a LAN switch only, you should have to do nothing special, since after the first router it's all a single LAN with unique IPs.
If they are cascaded I suppose that you have to configure each one of them, but don't take my word for it.

The port which your friends router uses to connect to his PC (that's what I gathered to be your question) does not really matter, since from the outside you are only talking to the router and the router then does the mapping of IPs and ports.
Zocat
Profile Joined April 2010
Germany2229 Posts
July 07 2013 16:40 GMT
#6404
On July 08 2013 00:11 mustache wrote:
C++ TCP socket programming question:

I've written a small chat program where the client can send a message to the server.


So you have a server running?
I'd let the clients connect to the server, let the server keep a list of currentlyConnectedClients and everytime a message arrives I would broadcast the message to each connectedClient as long as it's not the sender.

So basically all clients only need to know the server IP.

If it's a (small) local environment I would just send a connect-message to every possible IP and if you get an answer the server is found. Should be np for LAN etc, since your router would just act as a switch in your local network.

If you want something like PC-Router-[Internet]-Router-PC you would need to configure NAT on the routers as mentioned before. And your friend would have to tell you his IP.
mustache
Profile Joined April 2010
Switzerland309 Posts
July 07 2013 17:51 GMT
#6405
Thanks for all the answers so far. I will try configuring the router and see if it works like that.

One more question. with a program like MSN messenger, how do they get around the problem of router configuration? NAT traversal as mentioned? or do routers have standard settings for ports they forward to certain IP
Leafty
Profile Joined July 2012
France84 Posts
July 07 2013 19:36 GMT
#6406
MSN is connected to a server, and your client knows its address (or a way to get it). With outgoing connections, the NAT just does its job and lets you connect to the server. Then messages can go through the server and that allows group messaging too.

If you have a server, you can also try to get a direct connection between two clients between a NAT (that was used by Skype, don't know if it's still used today). Basically, you lure both NATs to believe the connection is an outgoing one. But for that you need a third party (the MSN server here) to coordinate the connection.
tec27
Profile Blog Joined June 2004
United States3727 Posts
July 07 2013 20:25 GMT
#6407
http://www.brynosaurus.com/pub/net/p2pnat/

There's a good paper about all the different ways to do NAT traversal. TCP Hole Punching would be the relevant one to you.
Can you jam with the console cowboys in cyberspace?
n0ise
Profile Joined April 2010
3452 Posts
Last Edited: 2013-07-08 18:55:11
July 08 2013 18:53 GMT
#6408
Java>>Threads Question:

Running some arbitrary simple code (printing first n even numbers or whatever) on 1 or more threads results in roughly the same execution time.

Is this expected? Seems really surprising to me.
supereddie
Profile Joined March 2011
Netherlands151 Posts
July 08 2013 20:51 GMT
#6409
Yes. There is overhead for using multiple threads (such as synchronisation) and simple code rarely benefits from multithreading.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
tec27
Profile Blog Joined June 2004
United States3727 Posts
July 09 2013 02:09 GMT
#6410
On July 09 2013 03:53 n0ise wrote:
Java>>Threads Question:

Running some arbitrary simple code (printing first n even numbers or whatever) on 1 or more threads results in roughly the same execution time.

Is this expected? Seems really surprising to me.

It very much depends on the code and environment. If all of the threads are competing for a single resource (e.g. a file descriptor), its expected that execution would see no speedup. If all the threads are running on a single core (and thus not actually parallel), its expected that execution would see no speedup.
Can you jam with the console cowboys in cyberspace?
n0ise
Profile Joined April 2010
3452 Posts
Last Edited: 2013-07-09 05:01:48
July 09 2013 04:51 GMT
#6411
On July 09 2013 11:09 tec27 wrote:
Show nested quote +
On July 09 2013 03:53 n0ise wrote:
Java>>Threads Question:

Running some arbitrary simple code (printing first n even numbers or whatever) on 1 or more threads results in roughly the same execution time.

Is this expected? Seems really surprising to me.

It very much depends on the code and environment. If all of the threads are competing for a single resource (e.g. a file descriptor), its expected that execution would see no speedup. If all the threads are running on a single core (and thus not actually parallel), its expected that execution would see no speedup.


they're not competing for a single resource, but how do you setup multi-core execution?

le - if you're referring to ExecutorService, I've also tested using that, obtaining the same results.
phar
Profile Joined August 2011
United States1080 Posts
July 09 2013 05:40 GMT
#6412
You mentioned printing, which could well be the single resource. If you have a bunch of real code in there, it's probably not a bottleneck, but if your code is literally just "print this shit"...

Also

for (i = 0; i < ... ; i+=2) {
printf (i);
}

does not parallelize, especially if you need stuff to be printed out in order.
Who after all is today speaking about the destruction of the Armenians?
n0ise
Profile Joined April 2010
3452 Posts
Last Edited: 2013-07-09 07:02:19
July 09 2013 06:53 GMT
#6413
On July 09 2013 14:40 phar wrote:
You mentioned printing, which could well be the single resource. If you have a bunch of real code in there, it's probably not a bottleneck, but if your code is literally just "print this shit"...

Also

for (i = 0; i < ... ; i+=2) {
printf (i);
}

does not parallelize, especially if you need stuff to be printed out in order.


they're not printing in order, but they are indeed printing... interesting. I'm basically trying to test the benefits of using more threads, without much success so far

from what i've read, it may also be because jvm automatically optimizes the workload on all cores by default.

le2: right, ok, tested without printing (just incrementing a personal field) and the execution times make much more sense now

much obliged, gentlemen
Leafty
Profile Joined July 2012
France84 Posts
July 09 2013 07:09 GMT
#6414
On July 09 2013 15:53 n0ise wrote:
Show nested quote +
On July 09 2013 14:40 phar wrote:
You mentioned printing, which could well be the single resource. If you have a bunch of real code in there, it's probably not a bottleneck, but if your code is literally just "print this shit"...

Also

for (i = 0; i < ... ; i+=2) {
printf (i);
}

does not parallelize, especially if you need stuff to be printed out in order.


they're not printing in order, but they are indeed printing... interesting. I'm basically trying to test the benefits of using more threads, without much success so far

from what i've read, it may also be because jvm automatically optimizes the workload on all cores by default.


Using multiple threads on a multi-core processor will only yield results if you have a parallelizable algorithm. And the speedup will be limited by the non-parallelizable portion of your algorithm.

In your case, it takes way more CPU cycles to print to the output than to compute even numbers, so you do not gain anything by parallelizing it.
Millitron
Profile Blog Joined August 2010
United States2611 Posts
July 09 2013 07:09 GMT
#6415
On July 09 2013 15:53 n0ise wrote:
Show nested quote +
On July 09 2013 14:40 phar wrote:
You mentioned printing, which could well be the single resource. If you have a bunch of real code in there, it's probably not a bottleneck, but if your code is literally just "print this shit"...

Also

for (i = 0; i < ... ; i+=2) {
printf (i);
}

does not parallelize, especially if you need stuff to be printed out in order.


they're not printing in order, but they are indeed printing... interesting. I'm basically trying to test the benefits of using more threads, without much success so far

from what i've read, it may also be because jvm automatically optimizes the workload on all cores by default.

le2: right, ok, tested without printing (just incrementing a personal field) and the execution times make much more sense now

much obliged, gentlemen

They may have not been printing in order due to unhandled race conditions. You have no control over what threads get the processor(s) at any given time, and so unless you explicitly use some concurrency library (Locks are a good one in Java), you can't trust anything involving timing, which includes ordering.

If you're only concerned with time-to-complete, and not the correctness of the output, don't print until the very end. Printing is painfully slow compared to practically everything else, and it is likely ruining any benefit of parallelization.
Who called in the fleet?
wherebugsgo
Profile Blog Joined February 2010
Japan10647 Posts
Last Edited: 2013-07-09 07:11:28
July 09 2013 07:09 GMT
#6416
this is conjecture, so take this with a grain of salt. If someone knows that something I've said is wrong, feel free to correct me-I'm basing this on my understanding of how parallelism works (my experience is mostly with MapReduce in Java and OpenMP in C)

there's no benefit if you're doing only one thing because there is nothing to parallelize. like phar said, it's likely that because in the first case all you were doing was printing, since every thread wants to dump something to System.out at the same time only one thread can execute at a time.

In fact it's probably slower than the serial case because of the overhead in dividing the work.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-07-10 12:15:30
July 10 2013 12:04 GMT
#6417
I've been wondering why software uses Windows Registry. As far as I know, the same can be done with a simple .conf file, and it's even portable, while Windows Registry needs to be manually exported to the new computer. Maybe there's something I'm missing as a detail?

Edit: Maybe users are that dumb that developers decide to hide config within the registry so that config files aren't deleted? Or is there another advantage?

On the other hand, http://en.wikipedia.org/wiki/Windows_Registry#Rationale sounds good to have individual registry for each user, but the same can be done with just config files. E.g. store configs in C:\Users\user or some other folder.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
July 10 2013 12:12 GMT
#6418
On July 10 2013 21:04 darkness wrote:
I've been wondering why software uses Windows Registry. As far as I know, the same can be done with a simple .conf file, and it's even portable, while Windows Registry needs to be manually exported to the new computer. Maybe there's something I'm missing as a detail?

Edit: Maybe users are that dumb that developers decide to hide config within the registry so that config files aren't deleted? Or is there another advantage?

I guess the only real advantage is that it's central to the whole computer, and I think the initial idea was to only store computer-wide settings there, concerning windows. Then it was opened and every single program decided that it would be a good idea to save settings in the registry.

It makes no sense to me either, anyone who has used linux for a decent amount of time will agree that it's far nicer to edit .ini and .cfg files than the fricking registry.
SgtCoDFish
Profile Blog Joined July 2010
United Kingdom1520 Posts
July 10 2013 12:22 GMT
#6419
On July 10 2013 21:04 darkness wrote:
I've been wondering why software uses Windows Registry. As far as I know, the same can be done with a simple .conf file, and it's even portable, while Windows Registry needs to be manually exported to the new computer. Maybe there's something I'm missing as a detail?

Edit: Maybe users are that dumb that developers decide to hide config within the registry so that config files aren't deleted? Or is there another advantage?

On the other hand, http://en.wikipedia.org/wiki/Windows_Registry#Rationale sounds good to have individual registry for each user, but the same can be done with just config files. E.g. store configs in C:\Users\user or some other folder.


I don't use it ever, but I can imagine it's useful for stuff you don't mind being (or that you want to be) globally accessible. The user can (well, should be able to) pick the place your program is installed to. They're not going to care about picking where in the registry your program writes data.

Take SC2; it writes APM data to the registry so that some razer devices can use it (the headphones that change colour). The registry lets them do that in a standard, pre-agreed place where it's not going to get in the way. That seems like a reasonable use of the registry to me.
misirlou
Profile Joined June 2010
Portugal3319 Posts
Last Edited: 2013-07-10 12:26:01
July 10 2013 12:25 GMT
#6420
On July 09 2013 15:53 n0ise wrote:
Show nested quote +
On July 09 2013 14:40 phar wrote:
You mentioned printing, which could well be the single resource. If you have a bunch of real code in there, it's probably not a bottleneck, but if your code is literally just "print this shit"...

Also

for (i = 0; i < ... ; i+=2) {
printf (i);
}

does not parallelize, especially if you need stuff to be printed out in order.


they're not printing in order, but they are indeed printing... interesting. I'm basically trying to test the benefits of using more threads, without much success so far

from what i've read, it may also be because jvm automatically optimizes the workload on all cores by default.

le2: right, ok, tested without printing (just incrementing a personal field) and the execution times make much more sense now

much obliged, gentlemen


If you really want to see speedup from Multi threading (and to some extent, cache hits) I would suggest you try to implement Matrix Multiplication or Computing Primes. Some modifications to said algorithms allow for a bigger speedup to it's single thread counterpart, and you can also check the difference in cache access vs ram access by splitting the work in blocks (for both single and multi thread, the difference is really HUGE)
Prev 1 319 320 321 322 323 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 4h 36m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft501
StarCraft: Brood War
Rain 2664
GuemChi 1715
Hyuk 598
Leta 289
ProTech168
Pusan 84
ZergMaN 34
Dewaltoss 27
Noble 24
Icarus 10
League of Legends
JimRising 681
Super Smash Bros
hungrybox582
Heroes of the Storm
Trikslyr39
Other Games
summit1g9216
PiGStarcraft211
Sick71
NeuroSwarm54
Organizations
Other Games
gamesdonequick644
[ Show 13 non-featured ]
StarCraft 2
• practicex 32
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2213
League of Legends
• Stunt520
Other Games
• Scarra770
• Shiphtur602
Upcoming Events
IntoTheTV X SOOP
4h 36m
ByuN vs Lambo
MaxPax vs Bunny
PiGosaur Cup
17h 36m
The PondCast
1d 3h
Kung Fu Cup
1d 4h
IntoTheTV X SOOP
2 days
SHIN vs GuMiho
Clem vs Classic
OSC
2 days
WardiTV Invitational
3 days
GSL
3 days
Epic.LAN
3 days
Replay Cast
3 days
[ Show More ]
Sparkling Tuna Cup
4 days
Epic.LAN
4 days
Yamato Cup
5 days
Map Test Tournament
5 days
WardiTV Weekly
6 days
Replay Cast
6 days
Rogue vs Classic
Liquipedia Results

Completed

Acropolis #5 - GSC
Blizzard Classic Cup 2026
HCC Season 3

Ongoing

Acropolis #5
KCM Race Survival 2026 Season 4
International ShieldBattery League
BSL Season 23
PGL Masters Bucharest 2026
Stake Ranked Episode 5
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026

Upcoming

IPSL Winter 2026-27
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
eXTREMESLAND 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.