Skip to content

Commit

Permalink
Fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Henri Symoneaux committed May 12, 2016
1 parent bec9831 commit bafd9f3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "rust-sctp"
version = "0.0.4"
version = "0.0.5"
description = "High level SCTP networking library"
repository = "https://github.com/phsym/rust-sctp"
documentation = "http://phsym.github.io/rust-sctp"
Expand Down
6 changes: 3 additions & 3 deletions examples/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ extern crate sctp;
use sctp::*;

fn main() {
// match SctpListener::bind("0.0.0.0:3868") {
match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
Ok(serv) => {
match SctpListener::bind("0.0.0.0:3868") {
// match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
Ok(serv) => {
println!("bound to {:?}", serv.local_addrs().unwrap());
// serv.set_timeout(5).unwrap();
match serv.accept() {
Expand Down
10 changes: 5 additions & 5 deletions examples/one_to_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ use sctp::*;

fn main() {
// Create a new Sctp endpoint, and bind it to one or more socket addresses
// let sock = match SctpEndpoint::bind("0.0.0.0:3868") {
let sock = match SctpEndpoint::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
let sock = match SctpEndpoint::bind("0.0.0.0:3868") {
// let sock = match SctpEndpoint::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
Ok(s) => s,
Err(e) => panic!("{:?}", e.kind())
};
println!("Bound to {:?}", sock.local_addrs().unwrap());

let mut buf = [0u8; 1024];

// Read a message
match sock.recv_from(&mut buf) {
Ok((len, stream, addr)) => println!("Received {} bytes from {} on stream {} from {}", len, addr, stream, addr),
Err(e) => println!("{:?}", e.kind())
};

sock.send_to(&mut buf, "191.168.1.2:3868", 6).unwrap();
}
10 changes: 5 additions & 5 deletions examples/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ use std::io::prelude::*;

fn main() {
// Create a new one-to-one stream
// match SctpStream::connect("127.0.0.1:3868") {
match SctpStream::connectx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
match SctpStream::connect("127.0.0.1:3868") {
// match SctpStream::connectx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
Err(e) => println!("{:?}", e.kind()),
Ok(mut peer) => {
// Set SCTP no delay
println!("{}", peer.has_nodelay().unwrap());
peer.set_nodelay(true).unwrap();
println!("{}", peer.has_nodelay().unwrap());

// Set socket send buffer size
let oldsize = peer.get_buffer_size(SoDirection::Send).unwrap();
peer.set_buffer_size(SoDirection::Send, 4096).unwrap();
println!("Set send buffer size to {} (was : {})", peer.get_buffer_size(SoDirection::Send).unwrap(), oldsize);

println!("Setting read timeout to 10 s");
peer.set_timeout(SoDirection::Receive, 10).unwrap();

// Write a message using the io::Write trait
peer.write_all("foo bar\n".as_bytes()).unwrap();
// Write a message on stream 6
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ impl SctpEndpoint {
/// Create a one-to-many SCTP endpoint bound to a single address
pub fn bind<A: ToSocketAddrs>(address: A) -> Result<SctpEndpoint> {
let raw_addr = try!(SocketAddr::from_addr(&address));
let sock = try!(SctpSocket::new(raw_addr.family(), SOCK_STREAM));
let sock = try!(SctpSocket::new(raw_addr.family(), SOCK_SEQPACKET));
try!(sock.bind(raw_addr));
try!(sock.listen(-1));
return Ok(SctpEndpoint(sock));
}

Expand Down Expand Up @@ -338,6 +339,7 @@ impl SctpListener {
let raw_addr = try!(SocketAddr::from_addr(&address));
let sock = try!(SctpSocket::new(raw_addr.family(), SOCK_STREAM));
try!(sock.bind(raw_addr));
try!(sock.listen(-1));
return Ok(SctpListener(sock));
}

Expand Down

0 comments on commit bafd9f3

Please sign in to comment.