Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sven Gestegård Robertz
LabComm
Commits
2e0fa68f
Commit
2e0fa68f
authored
Nov 29, 2013
by
Sven Gestegård Robertz
Browse files
added python test decoder and a server that only encodes
parent
4b757e87
Changes
4
Hide whitespace changes
Inline
Side-by-side
examples/tcp/example_tcp_client_decoder.py
0 → 100755
View file @
2e0fa68f
#!/usr/bin/python
import
os
import
sys
import
socket
import
rwsocket
if
not
any
(
'labcomm'
in
p
for
p
in
sys
.
path
):
sys
.
path
.
append
(
'../../lib/python'
)
import
labcomm
if
__name__
==
"__main__"
:
print
"Trying to connect..."
host
=
sys
.
argv
[
1
]
#'localhost'
port
=
sys
.
argv
[
2
]
#'8081'
addr
=
(
host
,
int
(
port
))
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
connect
(
addr
)
print
"Connected!"
d
=
labcomm
.
Decoder
(
labcomm
.
StreamReader
(
sock
))
while
True
:
try
:
data
,
decl
=
d
.
decode
()
if
data
:
print
data
except
KeyError
as
e
:
print
'KeyError : "%s"'
%
str
(
e
)
break
except
:
print
'exception...'
,
sys
.
exc_info
()[
0
]
break
examples/tcp/labcommTCPtest/server/OneShotServer.java
0 → 100644
View file @
2e0fa68f
package
labcommTCPtest.server
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.Socket
;
import
java.net.ServerSocket
;
import
se.lth.control.labcomm.LabCommDecoderChannel
;
import
se.lth.control.labcomm.LabCommEncoderChannel
;
import
labcommTCPtest.gen.FooSample
;
public
class
OneShotServer
{
//implements Handler {
private
OutputStream
out
;
public
OneShotServer
(
Socket
s
)
throws
IOException
{
out
=
s
.
getOutputStream
();
}
public
void
test
()
{
try
{
LabCommEncoderChannel
e
=
new
LabCommEncoderChannel
(
out
);
FooSample
.
register
(
e
);
FooSample
sample
=
new
FooSample
();
sample
.
x
=
17
;
sample
.
y
=
42
;
sample
.
t
=
1717
;
sample
.
d
=
0.42
;
printSample
(
"Server sending"
,
sample
);
FooSample
.
encode
(
e
,
sample
);
Thread
.
sleep
(
1
);
sample
.
x
++;
sample
.
y
--;
printSample
(
"Server sending"
,
sample
);
FooSample
.
encode
(
e
,
sample
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
...
args
)
{
String
server
=
"localhost"
;
int
port
=
9999
;
try
{
ServerSocket
ss
=
new
ServerSocket
(
port
);
Socket
s
=
ss
.
accept
();
OneShotServer
c
=
new
OneShotServer
(
s
);
c
.
test
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
void
printSample
(
String
header
,
FooSample
sample2
)
throws
Exception
{
System
.
out
.
println
(
header
);
System
.
out
.
format
(
"TestClient.invoke(%d, %d, %d, %f)\n"
,
sample2
.
x
,
sample2
.
y
,
sample2
.
t
,
sample2
.
d
);
}
}
examples/tcp/runpy
0 → 100755
View file @
2e0fa68f
#!/bin/sh
PYTHONPATH
=
../../lib/python ./example_tcp_client_decoder.py
examples/tcp/rwsocket.py
0 → 100644
View file @
2e0fa68f
import
socket
import
types
def
flush
(
self
):
pass
socket
.
socket
.
write
=
socket
.
socket
.
send
socket
.
socket
.
read
=
socket
.
socket
.
recv
socket
.
socket
.
flush
=
flush
# class rwsocket(socket.socket):
# write=socket.socket.send
# read=socket.socket.recv
# def flush(self):
# pass
# def accept(self):
# sock, addr = super(rwsocket, self).accept()
# # sock.write = types.MethodType(self.write, sock, sock.__class__)
# # sock.read = types.MethodType(self.write, sock, sock.__class__)
# sock.__class__ = rwsocket
# return (sock, addr)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment