Forums - TCP client not working

2 posts / 0 new
Last post
TCP client not working
son
Join Date: 9 Aug 17
Posts: 14
Posted: Thu, 2018-07-05 01:59

Hey

I have tested and debug TCP client in AT command. It could not connect to the tcp server.

 

in ATN

ctcp=192,168,1,44, 8000

(My TCP server is at 192.168.1.44 at port 8000)

It shows:

 connection error on the socket: 16385, session: 0

static int32_t session_create(sock_info_t *psession):

 if (qc_drv_net_connect(qc_api_get_qc_drv_context(), psession->sock_id, (struct sockaddr *)addr, len_addr))
{
LOG_ERR("connection error on the socket: %d, session: %d\n", psession->sock_id, num_session);
return -1;
}
 
I have tried to use directly qapi_connect:
if (qapi_connect(psession->sock_id, (struct sockaddr *)addr, len_addr) < 0)
 
But it is still shown the same error.
 
I suspect that qapi_connect has the problem.
 
I wonder if you could check to see the same error as mine and let me know how to fix the TCP client.
 
Thanks.
P.S.:  My TCP server test program has been tested in various cases, it works fine. It is written in python.
TCP server test:
python  tcp_server_echo.py
----------------------------------
 
#!/usr/bin/python
 
"""
A simple "tcp echo server" for demonstrating TCP usage.
The server listens for TCP packets and echoes any received
packets back to the originating host.
 
"""
 
import socket
import optparse
import time
import sys
 
 
def echo_server(host, port):
    print "TCP echo server"
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    try:
        s.bind((host, port))
        s.listen(1)
    except socket.error, msg:
        print "ERROR: ", msg
        s.close()
        s = None
 
    if s is None:
        sys.exit(1)
 
    while 1:
        print "Listening on: %s:%d"%(host, port)
        data_len = 0
        try:
            conn, addr = s.accept()
        except KeyboardInterrupt:
            print "Closing Connection"
            s.close()
            s = None
            sys.exit(1)
 
        print 'Incoming connection accepted: ', addr
 
        try:
            while 1:
                data = conn.recv(4096)
                if not data: break
                print time.strftime("%b %d %H:%M:%S ", time.localtime()), addr[0], ":", repr(data)
                print ""
                conn.send(data)
        except KeyboardInterrupt:
            print "Closing Connection"
            s.close()
            s = None
            sys.exit(1)
 
        conn.close()
 
if __name__ == '__main__':
    parser = optparse.OptionParser()
    parser.add_option("-p", "--port", dest="port", type="int", default=8000, help="Port to listen on [default: %default].")
    parser.add_option("--hostname", dest="hostname", default="", help="Hostname to listen on.")
 
    (options, args) = parser.parse_args()
 
    echo_server(options.hostname, options.port)
 

 

  • Up0
  • Down0
son
Join Date: 9 Aug 17
Posts: 14
Posted: Mon, 2018-07-09 09:44

TCP client works now. 

Firewall problem, so it could not connect.

Thanks

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.