-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a submit button and socketUtils.java
- Loading branch information
1 parent
b7aa98a
commit cae3a88
Showing
5 changed files
with
258 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package application; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.DataOutputStream; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.ConnectException; | ||
import java.net.Socket; | ||
import java.net.UnknownHostException; | ||
|
||
public class socketUtils | ||
{ | ||
Socket clientSocket=null; | ||
DataOutputStream outToServer=null; | ||
BufferedReader inFromServer=null; | ||
|
||
public boolean socketConnect() | ||
{ | ||
String ipAddress, portString; | ||
int portNumber; | ||
boolean rc=false; | ||
|
||
try | ||
{ | ||
File file = new File("config.txt"); | ||
if (file.exists()) | ||
{ | ||
BufferedReader br = new BufferedReader(new FileReader("config.txt")); | ||
|
||
|
||
ipAddress = br.readLine(); | ||
portString = br.readLine(); | ||
portNumber = Integer.parseInt(portString); | ||
br.close(); | ||
} | ||
else | ||
{ | ||
ipAddress = "localhost"; //127.0.0.1 and "localhost" aren't working | ||
portNumber = 3333; | ||
} | ||
|
||
|
||
|
||
clientSocket = new Socket(ipAddress, portNumber); | ||
|
||
outToServer = new DataOutputStream(clientSocket.getOutputStream()); | ||
inFromServer = new BufferedReader( | ||
new InputStreamReader(clientSocket.getInputStream())); | ||
|
||
rc= true; | ||
} | ||
catch (ConnectException ex) | ||
{ | ||
ex.printStackTrace(); | ||
} | ||
catch (UnknownHostException ex) | ||
{ | ||
ex.printStackTrace(); | ||
} | ||
catch (IOException ex) | ||
{ | ||
ex.printStackTrace(); | ||
} | ||
|
||
return rc; | ||
} | ||
|
||
public boolean sendMessage(String msg) | ||
{ | ||
boolean rc=false; | ||
|
||
try | ||
{ | ||
outToServer.writeBytes(msg + "\r\n"); | ||
rc = true; | ||
} | ||
catch (IOException e) | ||
{ | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
return rc; | ||
} | ||
|
||
public String recvMessage() | ||
{ | ||
String msg=null; | ||
|
||
try | ||
{ | ||
msg = inFromServer.readLine(); | ||
} | ||
catch (IOException e) | ||
{ | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
return msg; | ||
} | ||
|
||
public boolean closeSocket() | ||
{ | ||
boolean rc=false; | ||
|
||
try | ||
{ | ||
clientSocket.close(); | ||
rc=true; | ||
} | ||
catch (IOException e) | ||
{ | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
return rc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
04-08-2021 23.41.41 : SERVER : Transaction>kiosk#001,2,1.44 | ||
04-08-2021 23.41.42 : SERVER : quit | ||
04-08-2021 23.54.25 : SERVER : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.25 : SERVER : quit | ||
04-08-2021 23.54.26 : CLIENT : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.27 : SERVER : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.28 : SERVER : quit | ||
04-08-2021 23.54.28 : CLIENT : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.28 : SERVER : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.29 : SERVER : quit | ||
04-08-2021 23.54.29 : CLIENT : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.29 : SERVER : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.30 : SERVER : quit | ||
04-08-2021 23.54.30 : CLIENT : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.30 : SERVER : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.31 : SERVER : quit | ||
04-08-2021 23.54.31 : CLIENT : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.31 : SERVER : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.32 : SERVER : quit | ||
04-08-2021 23.54.32 : CLIENT : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.32 : SERVER : Transaction>kiosk#001,0,0.00 | ||
04-08-2021 23.54.33 : SERVER : quit | ||
04-08-2021 23.54.33 : CLIENT : Transaction>kiosk#001,0,0.00 |