aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-06 17:37:35 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-06 17:37:35 +0200
commit7aa211a8d7ae2efeebd9362699a1aea4b5690e3d (patch)
treee0af8720ee3b770688600a8ea025de2ce81e5017 /examples
parent7177367ae41a5e2d6ed401f60ee1455812dd8ffb (diff)
downloadsip-rs-7aa211a8d7ae2efeebd9362699a1aea4b5690e3d.tar
sip-rs-7aa211a8d7ae2efeebd9362699a1aea4b5690e3d.tar.bz2
sip-rs-7aa211a8d7ae2efeebd9362699a1aea4b5690e3d.tar.zst
start on sdp impl
Diffstat (limited to 'examples')
-rw-r--r--examples/server.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/examples/server.rs b/examples/server.rs
index 60a2b33..b58557a 100644
--- a/examples/server.rs
+++ b/examples/server.rs
@@ -9,12 +9,13 @@ use sip::{
method::Method,
response::Response,
status::Status,
+ uri::Uri,
},
transaction::TransactionUser,
- transport::tcp::TcpTransport,
+ transport::{tcp::TcpTransport, udp::UdpTransport},
};
use tokio::{
- net::{TcpListener, TcpStream},
+ net::{TcpListener, TcpStream, UdpSocket},
spawn,
};
@@ -23,6 +24,7 @@ async fn main() -> Result<()> {
env_logger::init_from_env("LOG");
let listener = TcpListener::bind("0.0.0.0:5060").await?;
info!("tcp listener bound to {}", listener.local_addr().unwrap());
+
loop {
let (stream, addr) = listener.accept().await?;
info!("connect {addr}");
@@ -51,11 +53,17 @@ async fn handle_client(stream: TcpStream, addr: SocketAddr) -> Result<()> {
Response {
status: Status::Ok,
headers: HeaderMap::new()
- .add(Contact(format!("<sip:{username}@{addr}>;expires=600")))
- .add(From(to.0))
- .add(To(from.0))
- .add(UserAgent("siptest v0.1.0".to_string()))
- .add(ContentLength(0)),
+ .add(Contact {
+ display_name: None,
+ uri: Uri {
+ content: format!("sip:username@{addr}"),
+ },
+ params: ";expires=600".to_string(),
+ })
+ .add(to)
+ .add(from)
+ .add(UserAgent("siptest v0.1.0".to_string())),
+ body: String::new(),
},
)
.await?;