Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
permocar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robert Hedman
permocar
Commits
ef5b1bb3
Commit
ef5b1bb3
authored
7 years ago
by
Robert Hedman
Browse files
Options
Downloads
Patches
Plain Diff
Somwehat workign tcp messaging
parent
d4efdb94
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+47
-1
47 additions, 1 deletion
src/main.rs
with
47 additions
and
1 deletion
src/main.rs
+
47
−
1
View file @
ef5b1bb3
...
...
@@ -2,6 +2,12 @@ use std::thread;
use
std
::
sync
::
mpsc
;
use
std
::
time
;
// stuff for tcp
use
std
::
io
::
prelude
::
*
;
use
std
::
net
::
TcpStream
;
use
std
::
net
::
TcpListener
;
use
std
::
str
;
// should the map matrix be two dim array of const size, vecs of dynamic, or what?
...
...
@@ -72,7 +78,7 @@ fn main() {
// update map
if
pos
.0
==
1000
000
{
if
pos
.0
==
2
000
{
println!
(
"mapper done."
);
request_location_tx
.send
(
false
)
.unwrap
();
break
;
...
...
@@ -84,9 +90,49 @@ fn main() {
});
let
server
=
thread
::
spawn
(||
{
let
listener
=
TcpListener
::
bind
(
"127.0.0.1:8080"
)
.unwrap
();
let
mut
stream
;
let
mut
message
=
[
0u8
;
13
];
match
listener
.accept
()
{
Ok
((
socket
,
addr
))
=>
{
println!
(
"server: new client: {:?}"
,
addr
);
stream
=
socket
;
thread
::
sleep
(
time
::
Duration
::
new
(
1
,
0
));
//loop {
match
stream
.read
(
&
mut
message
)
{
Ok
(
msg
)
=>
{
println!
(
"server got: {:?}, local message: {}"
,
msg
,
str
::
from_utf8
(
&
message
)
.unwrap
());
//stream.write(String::from("yo").as_bytes()).unwrap();
},
Err
(
e
)
=>
{
println!
(
"Some error in readToString in swerver: {}"
,
e
)},
}
//}
},
Err
(
e
)
=>
println!
(
"couldn't get client: {:?}"
,
e
),
}
});
thread
::
sleep
(
time
::
Duration
::
new
(
3
,
0
));
let
mut
stream
=
TcpStream
::
connect
(
"127.0.0.1:8080"
)
.unwrap
();
//thread::sleep(time::Duration::new(0,900*1000000));
//let written_size = stream.write(&['y' as u8,'o' as u8, '!' as u8]);
//println!("main wrote {:?} bytes to stream.", written_size);
let
written_size
=
stream
.write_all
(
"Main says hi."
.as_bytes
());
println!
(
"main wrote_all {:?} to stream."
,
written_size
);
//let mut message = String::with_capacity(127);
/*match stream.read_to_string(&mut message) {
Ok(m) => {println!("main got: {:?}", m)},
Err(e) => {println!("Main could not read to string: {:?}", e);},
};*/
println!
(
"Main wating for join."
);
mapper
.join
()
.unwrap
();
tracker
.join
()
.unwrap
();
println!
(
"Main wating for server join."
);
//drop(stream);
server
.join
()
.unwrap
();
println!
(
"end of main"
);
// pathfinder, takes a map and returns a list of nodes to aim for when driving
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment