Sign in to follow this  
Followers 0
0_00_0

Communicating with java (possible)?

1 post in this topic

Hey not sure just how advanced this is, but I thought it would be a cool idea to have a java server, autoIT client.

I'm having no difficulty connecting, I can tell there is a connection, but my java code stops at line 40, msg = inStream.readLine();

Is there going to be compatibility issues between the messages autoIT is sending and the ones java is expecting to receive?

autoIT client:

$c_Ip = "127.0.0.1"
$c_Port = 6424

TCPStartup()

$socket = TCPConnect($c_Ip, $c_Port)

if $socket = -1 Then
    msgbox(0, "Error", "Error Connecting")
EndIf

while True
    $msg = inputbox("Send msg", "Send msg to server")
    TCPSend($socket, $msg)
    
    sleep(1)
WEnd

Java server:

import java.net.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.io.BufferedReader;

public class Server {
    
        
    public Server() {
    }
    
    public static void main(String[] args) {
        final int port = 6424;
        
        
        Socket clientsocket = null;
        ServerSocket sSocket = null;
        BufferedReader in = null;
        InputStream ins = null;
        BufferedReader inStream = null;
        String msg = "";
        
        
        try{
            sSocket = new ServerSocket(port);
            
        }catch(IOException e){
            System.out.println("Error: " + e);
        }
        
        System.out.println("Starting server..");
        try{
            clientsocket = sSocket.accept();
        }catch(IOException e){
            System.out.println("Error: " + e);
        }
        
        System.out.println("Connection detected!");
        try{
            ins = clientsocket.getInputStream();
            InputStreamReader blah = new InputStreamReader(ins);
            inStream = new BufferedReader(blah);
            
        }catch(IOException aE){
            System.out.println("Error: " + aE );
        }
        
        while(true){
            try{
                msg = inStream.readLine();
                if(msg != ""){
                    System.out.println(msg);
                    msg = "";
                }
                ins = clientsocket.getInputStream();
                System.out.println("e" + msg);
                
            }catch(IOException aE){
                System.out.println("Error: " + aE);
                System.exit(0);
            }
            
        }
        
    }
}

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0