Erlang/OTP Forums

Author Message

<  Erlang  ~  TCP - Replying to a message (inet:peername question)

Amadeus
Posted: Tue Dec 01, 2009 12:46 pm Reply with quote
Joined: 23 Nov 2009 Posts: 4
Hey again!

I'm working on setting up a TCP connection (making a Peer-to-Peer client), and I've ran into some problems with dynamicly replying to messages I get. Basicly, I get a message do a couple of calculations and then want to reply to the one that sent me the message in the first place. So I try using this:
Code:
{ok, {PeerIP, PeerPort}} = inet:peername(MySocket)


But it seems that it returns the right IP but the wrong port, or at least I'm not listening to that port.
It works just perfect when I use two hard-coded ports.
Anyone here got any hints?

Cheers!
View user's profile Send private message
Karalabe
Posted: Thu Dec 03, 2009 5:09 pm Reply with quote
User Joined: 03 Jul 2009 Posts: 11
With TCP you always have a "server" and a "client". The server listens to incoming connections, the client connects to the server.

Cosider this:
You start the server at IP 192.168.0.1 listening on port 31415.
A client from IP 192.168.0.2 connects to the server.

This would mean, that the TCP/IP stack on the client computer will request an unused port from the operating system and initiate a connection from there.

If the OS returns port number 55555 then the connection will be between 192.168.0.1:31415 (server) and 192.168.0.2:55555 (client). If on the server node you ask for the peername of the client, you should get back {ok, {"192.168.0.2", 55555}}.
View user's profile Send private message
wuji
Posted: Mon Aug 27, 2012 7:45 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
detonate it successfully aboard the plane.Officials say al-Asiri also designed designed authentic jordans designed the bombs hidden in printers that were shipped from
to Chicago. The bombs were intercepted in Dubai and the the real jordans the U.K. after they'd been placed aboard cargo planes.In a
intelligence bulletin issued overnight, the FBI and the Department of of cheap polo ralph lauren of Homeland Security said the Yemen group "intends to
plots along multiple fronts, including renewed efforts to target Western Western [h4]imitation designer *beep*[/h4] Western aviation.""It doesn't take a great number of people to
the kind of attack that we had on September 11," 11," [h2]cheap designer *beep*[/h2] 11," said Richard Clarke, an ABC News consultant and former
House counterterrorism official. "That was less than two dozen people people [h2]cheap polo ralph lauren[/h2] people and it's clear that they have that number available
View user's profile Send private message
dongdongwu
Posted: Thu Sep 20, 2012 2:09 am Reply with quote
User Joined: 19 Sep 2012 Posts: 236
His good friend Diane said: "Christian Louboutin Men Shoes was a magician, he make shoes is immediately put his female people with legs and advantage. He understands women wanted to do and can make them into beautiful Cinderella." Madonna often in its concert wearing Christian louboutin high heels , and some famous superstar like Angelina jolie, mariah Carey, beyonce Knowles, the famous Japanese singer YaYouMei Hamasaki helps Christian Louboutin Men Shoes set up its powerful position. The youngest customers will count Tom cruise's daughter sully cruz. Louboutin made for only a pair of handmade Christian Louboutin high heel Shoes! Want to be more fashion? Put on Christian Louboutin Outlet !
Candy colors of the chalaza high-heeled shoes with lolita type allure, set full finely gem blue "neon shoes" is to need to use "sexy" to describe. Each pair are worth careful appreciation of lithe and graceful fairy ludaoli, what kind of most let you move?Christian Louboutin Men Shoes that one brush red is always cannot resist the temptation, Christian Louboutin men outlet continue to use the days of high 8cm above slender heel proclaim the sexy and luxuriant. The bowknot on black pointed high-heeled shoes with sharp rivet concomitant, wild python met enchanting color printing grain, It is that pairs of high-heeled shoes lets Carrie more feminine flavour. Like Christian Louboutin for men her word.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum