• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 01:51
CET 07:51
KST 15:51
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
StarCraft Evolution League (SC Evo Biweekly) RSL Offline Finals Info - Dec 13 and 14! RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread ZeroSpace Megathread Nintendo Switch Thread The Perfect Game Path of Exile
Dota 2
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 Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1574 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
Portugal3241 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
Replay Cast
00:00
WardiTV Mondays #62
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 132
SortOf 93
-ZergGirl 21
StarCraft: Brood War
Stork 926
Tasteless 221
Shine 65
Sacsri 61
Bale 40
ZergMaN 14
Dota 2
NeuroSwarm125
febbydoto36
League of Legends
JimRising 630
Other Games
summit1g11258
WinterStarcraft559
C9.Mang0327
ViBE132
Mew2King48
Organizations
Other Games
gamesdonequick706
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH134
• practicex 31
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1248
Upcoming Events
The PondCast
3h 10m
OSC
9h 10m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
17h 10m
Korean StarCraft League
1d 20h
CranKy Ducklings
2 days
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
3 days
[ Show More ]
WardiTV 2025
3 days
OSC
3 days
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
4 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
4 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
5 days
StarCraft2.fi
6 days
Tenacious Turtle Tussle
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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 © 2025 TLnet. All Rights Reserved.