d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Learning Proxy C++
Add Reply New Topic New Poll
Member
Posts: 16,144
Joined: Mar 27 2008
Gold: 14,618.00
Feb 23 2014 11:44am
hi guys,

for my current job i need to learn the basics of proxies.
i wrote a proxy in c++ with winsock2 and it's obvious that it only accepts one connection since i coded it like this.

my thought was, when i start the application twice, the two proxies could handle two connection... how wrong i was ~~
(i hoped that the first proxy kind of "stops listening for new connection" on the port since it already has his connection, so the second proxy could be the only one listening for new connection :/ )
my goal now is to find an experienced network-coder on jsp that tells me how (or if) i can solve this without changing the code.

someone knows the problem?
is it only possible to create one connection since i use the same ports for both applications?
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Feb 23 2014 11:04pm
You should modify your application to keep listening. Maybe you could close the listening socket after a connection has been made - I'm not sure about that; but you definitely can't listen on the same port twice.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 24 2014 03:32am
Quote (KrzaQ2 @ Feb 24 2014 01:04am)
You should modify your application to keep listening. Maybe you could close the listening socket after a connection has been made - I'm not sure about that; but you definitely can't listen on the same port twice.


This. You can't claim the same listening port which is already being listened on. Either close the listening socket, or actually learn how to handle concurrent connections (which is easy as hell and you should be embarrassed that you don't know how seeing how there's only a million tutorials on the internet in every language). I doubt you made a proxy to spec if you can't even figure out how to create a multi connection socket application. The way you said you wanted to solve it without changing the code makes it sound as if you stole the code off the internet and can't comprehend it enough to change it.

This post was edited by AbDuCt on Feb 24 2014 03:34am
Member
Posts: 16,144
Joined: Mar 27 2008
Gold: 14,618.00
Feb 24 2014 07:28am
Quote (AbDuCt @ 24 Feb 2014 10:32)
This. You can't claim the same listening port which is already being listened on. Either close the listening socket, or actually learn how to handle concurrent connections (which is easy as hell and you should be embarrassed that you don't know how seeing how there's only a million tutorials on the internet in every language). I doubt you made a proxy to spec if you can't even figure out how to create a multi connection socket application. The way you said you wanted to solve it without changing the code makes it sound as if you stole the code off the internet and can't comprehend it enough to change it.


"if you stole the code" -> ofc i stole the code, why the hell should i rewrite the wheel
"there are plenty of tutorials" -> thats where i stole the code without rewriting
"can't comprehend it enough" -> i can actually but i'm too lazy
"proxy to spec" -> i just want to forward traffic, one ip to one ip, one port to one port. btw, specing is illegal if you look at jsp rules
"embarassed" -> ofc i'm not embarassed, you should be embarassed to insult me that i wasn't seeing the million tutorials...

my steps usually:
1) google 2) do it yourself
but now i thought why not revive the more or less dead programmer subforum :) so it was
1) goolgle 2) jsp 3) do it yourself

thanks though :)
topic can be closed, i'll rewrite the code since none of the experts here knows an easier solution
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 24 2014 07:47am
Quote (Richter @ Feb 24 2014 08:28am)

"can't comprehend it enough" -> i can actually but i'm too lazy


You thought you could open the application twice and that would allow 2 separate connections to be processed with the same socket. For this reason alone, you don't understand the fundamentals of sockets or concurrent programming.

Quote

topic can be closed, i'll rewrite the code since none of the experts here knows an easier solution


You were told that it is impossible. You don't understand what you are doing, and clearly don't understand the answer given to you. You'll rewrite the code? Doubtdul.

Member
Posts: 16,144
Joined: Mar 27 2008
Gold: 14,618.00
Feb 24 2014 09:54am
Quote (Minkomonster @ 24 Feb 2014 14:47)
You thought you could open the application twice and that would allow 2 separate connections to be processed with the same socket. For this reason alone, you don't understand the fundamentals of sockets or concurrent programming.

so only one http connection is possible, since they use port 80?
:bonk:
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 24 2014 10:24am
Quote (Richter @ Feb 24 2014 10:54am)
so only one http connection is possible, since they use port 80?
:bonk:


You don't understand the difference between a source port and a destination port. Your browser can request two different source ports and create two separate sockets that connect to a server address on port 80 for http. The server has an application that listens to port 80 and just takes the request and processes it.

This is different then what you are expecting. You for some reason expect your browser is creating a single socket and forwarding all http traffic through it?
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 24 2014 01:21pm
Quote
"proxy to spec" -> i just want to forward traffic, one ip to one ip, one port to one port. btw, specing is illegal if you look at jsp rules


Spec is short for specification which means there is a whole proxy binary protocol that you need to follow in order to forward and relay traffic packets (I don't know how this violates jsp rules?). You don't just connect and go whilly nilly sending shit. It's okay though for someone who needs something for work but doesn't take the time to learn what they are using by stealing others work I don't blame you.

For you're knowledge here is a wiki entry with all four proxy protocols (http, socks4, socks4a, socks5): http://en.wikipedia.org/wiki/SOCKS

Quote
topic can be closed, i'll rewrite the code since none of the experts here knows an easier solution


I told you how to fix it. It is one line of code, you just can't program worth shit.

Code
accept(listensocket);
closesocket(Listensocket); //close the listening socket after accepting a socket. This will allow a second application to start listening on the source port.


Quote (Minkomonster @ Feb 24 2014 12:24pm)
You don't understand the difference between a source port and a destination port. Your browser can request two different source ports and create two separate sockets that connect to a server address on port 80 for http. The server has an application that listens to port 80 and just takes the request and processes it.

This is different then what you are expecting. You for some reason expect your browser is creating a single socket and forwarding all http traffic through it?



Meh, I'd hate to be his company who is paying him to "write a proxy for work." He might as well download SQUID or some other Linux based proxy if he is just going to rip peoples work and call it his own, at least then it would be stable and not shit.


This post was edited by AbDuCt on Feb 24 2014 01:31pm
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Feb 24 2014 09:06pm
Quote (Richter @ 24 Feb 2014 14:28)
topic can be closed, i'll rewrite the code since none of the experts here knows an easier solution
Look up rinetd, it's a simple tcp connection bouncer. You could have asked about already existing solutions, not make it seem like you were actually trying (and failing) to learn.
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 24 2014 09:24pm
Quote (Richter @ Feb 23 2014 12:44pm)

i wrote a proxy in c++ with winsock2 and it's obvious that it only accepts one connection since i coded it like this.


to

Quote
"if you stole the code" -> ofc i stole the code, why the hell should i rewrite the wheel
"there are plenty of tutorials" -> thats where i stole the code without rewriting
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll