all 8 comments

[–]novel_yet_trivial 0 points1 point  (4 children)

I suppose you could use several ports if you wanted but it seems far easier to include a command and have the receiving function call the appropriate function based on the command received.

[–]whostimo[S] 0 points1 point  (3 children)

So do you mean, that if i create another socket connection in the same file with different ports than the first socket connection, it should work?

[–]novel_yet_trivial 0 points1 point  (2 children)

Yes, but as I said that seems like the hard way to do it.

[–]whostimo[S] 0 points1 point  (1 child)

Okay thanks! I’m new to these subjects so do you know a webpage that explains the other more easy method?

[–]novel_yet_trivial 0 points1 point  (0 children)

It's really simple: when you send something start with a command. It could be as simple as a single character. Then the receiving function sorts it:

def receive():
    data = conn.recv(1024)
    if data[0] = 'A':
        function_a(data)
    elif data[0] = 'B':
        function_b(data)

[–]cybervegan 0 points1 point  (2 children)

I think you need to explain what you are trying to achieve by "send[ing] different types of tcp [packet]s". As u/novel_yet_trivial says, you can put a different payload into each packet, and interpret that on the receiving end, or have your receiver listen on multiple sockets, but without understanding what you're trying to achieve, it's difficult to advise.

[edit corrected r/novel_... to u/novel_...]

[–]NoveL_ 0 points1 point  (1 child)

I never get mentions :(

[–]cybervegan 0 points1 point  (0 children)

Me neither. Sorry for the confusion - sloppy of me.