Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ChessTrack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Aylen Ricca
ChessTrack
Commits
30a1ef2c
Commit
30a1ef2c
authored
10 years ago
by
Aylen Ricca
Browse files
Options
Downloads
Patches
Plain Diff
basic server
parent
ca0d3e6f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ProyectoAndroid/ChessTrack/src/uy/edu/chesstrack/communication/Server.java
+22
-80
22 additions, 80 deletions
...hessTrack/src/uy/edu/chesstrack/communication/Server.java
with
22 additions
and
80 deletions
ProyectoAndroid/ChessTrack/src/uy/edu/chesstrack/communication/Server.java
+
22
−
80
View file @
30a1ef2c
...
...
@@ -2,6 +2,7 @@ package uy.edu.chesstrack.communication;
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.OutputStreamWriter
;
...
...
@@ -13,102 +14,43 @@ import java.net.UnknownHostException;
import
android.app.Activity
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.util.Log
;
import
android.widget.TextView
;
public
class
Server
{
private
static
final
String
TAG
=
"SERVER"
;
private
ServerSocket
serverSocket
;
Handler
updateConversationHandler
;
Thread
serverThread
=
null
;
private
TextView
tex
t
;
private
Socket
clientSocket
;
private
BufferedReader
input
;
private
DataOutputStream
outpu
t
;
public
static
final
int
SERVERPORT
=
6000
;
public
static
final
int
SERVERPORT
=
5555
;
public
Server
()
{
updateConversationHandler
=
new
Handler
();
this
.
serverThread
=
new
Thread
(
new
ServerThread
());
this
.
serverThread
.
start
();
clientSocket
=
null
;
try
{
serverSocket
=
new
ServerSocket
(
SERVERPORT
);
clientSocket
=
serverSocket
.
accept
();
this
.
input
=
new
BufferedReader
(
new
InputStreamReader
(
this
.
clientSocket
.
getInputStream
()));
String
read
=
input
.
readLine
();
Log
.
i
(
TAG
,
"line="
+
read
);
this
.
output
=
new
DataOutputStream
(
this
.
clientSocket
.
getOutputStream
());
this
.
output
.
writeBytes
(
new
String
(
"AYLEN RICCA"
));
//(read.toCharArray());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
void
Stop
()
{
try
{
serverSocket
.
close
();
clientSocket
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
class
ServerThread
implements
Runnable
{
public
void
run
()
{
Socket
socket
=
null
;
try
{
serverSocket
=
new
ServerSocket
(
SERVERPORT
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
while
(!
Thread
.
currentThread
().
isInterrupted
())
{
try
{
socket
=
serverSocket
.
accept
();
CommunicationThread
commThread
=
new
CommunicationThread
(
socket
);
new
Thread
(
commThread
).
start
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
class
CommunicationThread
implements
Runnable
{
private
Socket
clientSocket
;
private
BufferedReader
input
;
private
BufferedWriter
output
;
public
CommunicationThread
(
Socket
clientSocket
)
{
this
.
clientSocket
=
clientSocket
;
try
{
this
.
input
=
new
BufferedReader
(
new
InputStreamReader
(
this
.
clientSocket
.
getInputStream
()));
this
.
output
=
new
BufferedWriter
(
new
OutputStreamWriter
(
this
.
clientSocket
.
getOutputStream
()));
String
str
=
"AYLEN RICCA"
;
PrintWriter
out
=
new
PrintWriter
(
this
.
output
);
out
.
println
(
str
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
void
run
()
{
while
(!
Thread
.
currentThread
().
isInterrupted
())
{
try
{
String
read
=
input
.
readLine
();
updateConversationHandler
.
post
(
new
updateUIThread
(
read
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
class
updateUIThread
implements
Runnable
{
private
String
msg
;
public
updateUIThread
(
String
str
)
{
this
.
msg
=
str
;
}
@Override
public
void
run
()
{
text
.
setText
(
text
.
getText
().
toString
()+
"Client Says: "
+
msg
+
"\n"
);
}
}
}
\ No newline at end of file
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