• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:38
CEST 08:38
KST 15:38
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Reynor: GSL Loss Wasn't About Preparation Format12[IPSL] Spring 2026 Grand Finals - This Weekend!1Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Is the larve respawn broken? Weekly Cups (July 6 - 12): Protoss strike back Serral wins HomeStory Cup 29 Yamato Cup Series Interview with an American 16 Year Old Grandmaster
Tourneys
WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29 Vespene Cup #1 — $300+ USD, July 10
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
Etiquete rules in Asl? Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) screpdb: new Starcraft reporting tool ASL 22 Proposed Map Pool BSL Season 22 Full Overview & Conclusion
Tourneys
[Megathread] Daily Proleagues [ASL22] Wildcard Qualifier [IPSL] Spring 2026 Grand Finals - This Weekend! IPSL Spring 2026 Top 4!
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
Path of Exile Nintendo Switch Thread General RTS Discussion Thread Stormgate/Frost Giant Megathread Summer Games Done Quick 2026!
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread UK Politics Mega-thread YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Movie Discussion! Series you have seen recently...
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Tennis[sport] Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
Gauntlet SC2: A Retrospectiv…
Ctone23
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 11254 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 States3702 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 States3702 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
Portugal3306 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 2h 22m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft800
ProTech171
Nina 125
StarCraft: Brood War
GuemChi 3889
actioN 129
ZergMaN 78
Bale 24
Icarus 10
Dota 2
NeuroSwarm207
Fuzer 64
League of Legends
JimRising 692
Counter-Strike
Coldzera 1375
Other Games
summit1g6998
ceh9249
Maynarde154
XaKoH 152
Organizations
Other Games
gamesdonequick2649
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 15 non-featured ]
StarCraft 2
• Berry_CruncH318
• Light_VIP 12
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota279
League of Legends
• Rush1407
• Stunt403
Upcoming Events
Replay Cast
2h 22m
CrankTV Team League
4h 22m
Replay Cast
1d 2h
CrankTV Team League
1d 4h
Replay Cast
1d 17h
RSL Revival
2 days
Clem vs Lambo
Scarlett vs Cure
CranKy Ducklings
2 days
IPSL
2 days
Dragon vs Hawk
RSL Revival
3 days
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
3 days
[ Show More ]
IPSL
3 days
Bonyth vs Ret
WardiTV Weekly
4 days
Monday Night Weeklies
4 days
PiGosaur Cup
5 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-07-13
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026

Upcoming

Escore Tournament S3: W3
ASL S22 SEASON OPEN Day 1
Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
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.