Hello,
I have two code snipets that I need converted to FWH, can someone help convert for me? I am happy to pay someone for their time. Please send me an e-mail at Darrell.Ortiz AT cdmsoft.com if you are interested.
Thank you,
// CODE 1-----------------------------------------------------------------------------
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.util.Date;
public class TcpClientUtil
{
private static final int BUFSIZE = 50;
Socket socket = null;
OutputStream out = null;
InputStream in = null;
BufferedOutputStream bufferedOutputStream=null;
BufferedInputStream bufferedInputStream =null;
String hostServer = "192.168.1.107"; //149.99.39.146
int hostPort = 9100;//50030
int socketTimeout = 10000;
boolean connected = false;
FileWriter s;
Charset charset = Charset.forName("ISO-8859-1");
CharsetDecoder decoder = charset.newDecoder();
CharsetEncoder encoder = charset.newEncoder();
public TcpClientUtil() {
}
public TcpClientUtil(String HostServer, int HostPort, int SocketTimeout){
hostServer = HostServer;
hostPort = HostPort;
socketTimeout = SocketTimeout;
}
public FileWriter getLogger() {
return s;
}
public void setLogger(FileWriter s) {
this.s = s;
}
public boolean ConnectSocket() {
//Create socket connection
try
{
if(socket == null)
{
socket = new Socket();
socket.connect(new InetSocketAddress(hostServer, hostPort), socketTimeout);
connected = true;
bufferedOutputStream = new BufferedOutputStream(socket.getOutputStream());
bufferedInputStream = new BufferedInputStream(socket.getInputStream());
}
}
catch (UnknownHostException e)
{
System.out.println("Unknown host: kq6py.eng");
//System.exit(1);
connected = false;
}
catch (IOException e)
{
System.out.println("No I/O");
// System.exit(1);
connected = false;
}
return connected;
}
private boolean DisconnectSocket(){
try
{
if(socket!=null)
{
bufferedInputStream.close();
socket.close();
connected = false;
}
}
catch (IOException e)
{
System.out.println("Could not close socket");
System.exit(-1);
connected = false;
}
return connected;
}
public String SendRequest(String dataPacket){
String result = "";
byte[] bsRequest = null;
byte[] bsResponse = new byte[BUFSIZE];
int rcvMsgSize;
try{
//Encode request
System.out.println(new Date().toString() + " : Start Encode Request.") ;
//s.write(new Date().toString() + " : Start Encode Request.\r\n");
bsRequest = dataPacket.getBytes();
System.out.println(new Date().toString() + " : Stop Encode Request.") ;
//s.write(new Date().toString() + " : Stop Encode Request.\r\n");
//Send Request
if(bsRequest != null){
System.out.println(new Date().toString() + " : Start Writing Request to socket.") ;
//s.write(new Date().toString() + " : Start Writing Request to socket.\r\n");
for (int u = 0; u < bsRequest.length; u++) {
try {
//out.write(bsRequest[u]);
bufferedOutputStream.write(bsRequest[u]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
bufferedOutputStream.flush();
System.out.println("Sent data packet to printer");
boolean disconnected = DisconnectSocket();
System.out.println("Disconnected from printer");
}
}catch(Exception ex){
result = "ERROR : " + ex.getMessage();
}
return result;
}
private byte[] getDataPacket(String data){
byte[] b = null;
try{
String dataPacket = FileUtil.getContentsAsString("D:\\Argo Wireless\\Code\\sourcetag\\pocs\\TagPrintingPOC\\labels\\from Vijay\\Test.zpl");
b = dataPacket.getBytes();
}catch(Exception ex){
System.out.println(ex.getMessage());
}
return b;
}
private byte[] concat(byte[] bs1, byte[] bs2)
{
byte[] returnArray = new byte[bs1.length + bs2.length];
System.arraycopy(bs1, 0, returnArray, 0, bs1.length);
System.arraycopy(bs2, 0, returnArray, bs1.length, bs2.length);
return returnArray;
}
private String DecodeDataPacket(byte[] bs){
String result = null;
try{
result = new String(bs,"US-ASCII");
}catch(Exception ex){
result = "ERROR : " + ex.getMessage();
}
return result;
}
}
// CODE 2-----------------------------------------------------------------------------
private boolean printTags(String dataPacket, String hostName){
boolean result = false;
try{
//Connect to Server
TcpClientUtil printer = new TcpClientUtil(hostName,
Integer.parseInt(printerport),
Integer.parseInt(printerconnectiontimeout));
boolean connected = printer.ConnectSocket();
if(connected == true){
logger.info(new Date().toString() + " : Connected To Printer.\r\n");
String response = printer.SendRequest(dataPacket);
return true;
}
}catch(Exception ex){
logger.info(new Date().toString() + " : " + ex.getMessage());
return false;
}
return result;
}