SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By ayazalavi
#161576
Hi,

I am trying to create TCP socket to connect to Wifly. I am trying to get connected via following code but its not working, no response from wifly. IP and port are correct and device is connected to adhoc wifi generated by wifly module. Let me know if I am doing any thing wrong.
Code: Select all
InetAddress serverAddr = InetAddress.getByName(SERVERIP);
 
            Log.e("TCP Client", "C: Connecting...");
 
            //create a socket to make the connection with the server
            Socket socket = new Socket(serverAddr, SERVERPORT);
 
            try {
 
                //send the message to the server
                 out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
 
                Log.e("TCP Client", "C: Sent.");
 
                Log.e("TCP Client", "C: Done.");
 
                connected = true;
                //receive the message which the server sends back
                in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
 
                //in this while the client listens for the messages sent by the server
                while (mRun) {
                    serverMessage = in.readLine();
 
                    if (serverMessage != null && mMessageListener != null) {
                        //call the method messageReceived from MyActivity class
                        mMessageListener.messageReceived(serverMessage);
                    }
                    serverMessage = null;
 
                }
 
 
                Log.e("RESPONSE FROM SERVER", "S: Received Message: '" + serverMessage + "'");
 
 
            } catch (Exception e) {
 
                Log.e("TCP", "S: Error", e);
 
            } finally {
                //the socket must be closed. It is not possible to reconnect to this socket
                // after it is closed, which means a new socket instance has to be created.
                socket.close();
            }
By khanjan2khan
#161644
It won't listen in adhoc mode... Use it as infrstructure mode... And you still using adhoc.. update your firmware and use soft AP mode...
By ayazalavi
#161715
I am successfully been able to connect to wifly adhoc wifi via WifiManager class but I am unable to telnet into another device with known ip connected to that wifly module. Why is that?
By khanjan2khan
#161895
check the configurations of the receiving module.... Or else check if there is a tcp connection made.. Use port peeker to check...