Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

tls1.2 - Connecting to Socket over TCP but server is not receiving it

I'm attempting to connect to a socket connection and post a 'login' command but the server doesn't seem to be receiving my command.

I would provide the hostname but it's IP restricted so I don't believe that would provide you any benefit.

import socket
import ssl
import os

hostname = 'example.hostname.come'
context = ssl.create_default_context()
loginCommand = 'login username password'

# Create a client socket
socketInstance = socket.socket();

# Get an instance of SSLSocket
sslSocketInstance = context.wrap_socket(socketInstance, server_hostname=hostname);
sslSocketInstance.connect((hostname, 14555));
# Connect to a server

# Send Login Details
print('Sending Message');
sslSocketInstance.sendall(loginCommand.encode());
print('Message Sent');

# Receive Response
print('Checking Response');
received = sslSocketInstance.recv(1024);
print('Response Received');
print(received.decode());

The server is then times out after 1 minute (as stated in the documentation) and returns: ERR no login message received. This is the servers errors message so I am connecting and can retrieve just not send my message.

I have attempted a few different approached like adding a socket.listen(1) but I was never able to get this working. This was the only approach which I was able to receive a response from the server. I have also attempted socket.send(data) but same response.

Also important to note the request must be wrapped in TLS when creating the socket connection. I assume this is done when I complete wrap_socket.

Apologies for my noobness regard everything sockets.

question from:https://stackoverflow.com/questions/66056128/connecting-to-socket-over-tcp-but-server-is-not-receiving-it

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

With help from @user207421, I was able to determine that I needed a line terminator. I added a to the send of my request and this successfully returned.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...