• Post Reply Bookmark Topic Watch Topic
  • New Topic

Communication between nodes in a simulated p2p network scenario  RSS feed

 
irene floris
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I'm new in this forum.
I need your precious help. I'm realizing a project in which I have to simulate a peer-to-peer network scenario in order to apply some algorithms.
I've created the network made of node objects and links between them, but now I have to manage the communication between nodes.
I'm a bit of a newbie, so I think I should use sockets, but I don't know whether to use the package java.net.* or not, because the network I'm creating isn't actually real but just simulated.
Or should I implement some socket-like classes from scratch?


Also, in a peer to peer network, should I give each node two sockets? (server and client) ?
How should I handle this?

Thank you for your advices.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
irene floris wrote:
I'm a bit of a newbie, so I think I should use sockets, but I don't know whether to use the package java.net.* or not, because the network I'm creating isn't actually real but just simulated.
Or should I implement some socket-like classes from scratch?


Why would you want to do that? Sockets work even without a network (loopback) -- so you can use sockets, even if the network isn't "real". Besides, isn't it easier to not have to simulate anything? ...

Henry
 
irene floris
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to simulate this network with many nodes (each of them has an IP address and a port that I assigned randomly).
Maybe I'm missing something...how should you approach this? Thank you
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
irene floris wrote:I have to simulate this network with many nodes (each of them has an IP address and a port that I assigned randomly).
Maybe I'm missing something...how should you approach this? Thank you


With network communications, the pair of IP address and port must be unique. In the case of the loopback interface, the pair must still be unique. The only difference is, with the loopback, the IP address is the same (the localhost address). Manage the IP address and port as a pair, and the coding should be very similar.

Henry
 
irene floris
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah but I've tried to code something, and when I use some ip different from loopback, I receive some BindException. It works only with loopbacks.
Should I give to every node a different loobpack address?
And is there any example for the communication between the two parties (exchange of message objects) ?
Thank you
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
irene floris wrote: when I use some ip different from loopback, I receive some BindException.


The BindException exception means that you are either using an invalid IP address (or an invalid port). If you don't know what valid address / port to use, then talk to your system administrator.

irene floris wrote:
Should I give to every node a different loobpack address?


Doubt it. Most systems are only configured with one loopback interface. And even with multiple loopback interfaces, they don't loop with each other -- only within the same interface. And of course, loopback only allows for communication on the same machine.

Henry
 
irene floris
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I do something like this

(with port and IP chosen just for trying) it works. But with any other address (not loopback) i get this:
java.net.BindException: Cannot assign requested address: JVM_Bind
how can I resolve this issue? I want to use randomly picked IP to simulate this network...
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
irene floris wrote:Cannot assign requested address: JVM_Bind
how can I resolve this issue? I want to use randomly picked IP to simulate this network...


It doesn't work that way. You must specify a valid address, which is used to resolve a NIC.

If you want a virtual network (which the loopback kinda is), you should consider installing a VM, such as VmWare.

Henry
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What operating system are you deplyoing on? Linux networking is quite flexible -- you can easily assign multiple IP address to a single network interface, or create dummy network interfaces which are not backed by any actual networking hardware.

For example:
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:730636 errors:0 dropped:0 overruns:0 frame:0
          TX packets:730636 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:46096277 (43.9 MiB)  TX bytes:46096277 (43.9 MiB)

lo:peer1  Link encap:Local Loopback
          inet addr:127.5.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1

lo:peer2  Link encap:Local Loopback
          inet addr:127.5.0.2  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1

lo:peer3  Link encap:Local Loopback
          inet addr:127.5.0.3  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1

lo:peer4  Link encap:Local Loopback
          inet addr:127.5.0.4  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1

lo:peer5  Link encap:Local Loopback
          inet addr:127.5.0.5  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!