-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsuixy_chat.java
More file actions
74 lines (62 loc) · 1.5 KB
/
suixy_chat.java
File metadata and controls
74 lines (62 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.net.Socket;
import java.io.IOException;
import java.io.OutputStream;
import java.io.InputStream;
public class suixy_chat
{
public static void chatConsole(String IPAddress, int port)
{
try
{
suixy.out("Trying to connect to server at " + IPAddress + " on port " + port + " ...");
Socket socket = new Socket(IPAddress, port);
//Setup input and output streams
InputStream inStream = socket.getInputStream();
OutputStream outStream = socket.getOutputStream();
String command = "";
boolean running = true;
//Set the Streams
libsuix.outStream = outStream;
libsuix.inStream = inStream;
//Get the username
String username = libsuix.getUsername();
//Get the channel
String channel = libsuix.getChannel();
while(running)
{
System.out.print("["+username+"/"+channel+"]>>> ");
command = IO.readCommand(System.in);
if(command.equals("quit"))
{
return;
}
//Set my username
else if(command.equals("/nick"))
{
//Get the requested username
username = IO.readCommand(System.in);
//Set username
libsuix.setUsername(username);
}
//Anything else is a message
else
{
String errorReturn = libsuix.sendMessage(command);
if(errorReturn.equals("MESSAGE_SENT"))
{
//message has been sent then
}
else
{
//error
System.out.print("Error sending message");
}
}
}
}
catch(IOException err)
{
suixy.out("Error: " + err.getMessage());
}
}
}