Giter Site home page Giter Site logo

Rx from python about 42 HOT 7 OPEN

mhmodayman avatar mhmodayman commented on August 17, 2024
Rx from python

from 42.

Comments (7)

ericstoneking avatar ericstoneking commented on August 17, 2024

Hi Mahmoud,

I see two possible problems. First, try making the IPC Mode be TX instead of RX. Then, make the number of TX prefixes be 1 instead of zero, and add the line
"SC" ! Prefix 0

It may help if I explain that "Tx" is slang for "transmit" and "Rx" is slang for "receive". If both ends of the socket are in Rx mode, then everyone is listening but no one is talking :-) Also, a non-zero number of TX prefixes are needed for Tx to actually transmit something. If "SC" works for you, then we can talk about how to refine what is being sent.

Your python looks plausible, but I'm not expert enough either in python or sockets to say with confidence.

Regards,
-Eric

from 42.

mhmodayman avatar mhmodayman commented on August 17, 2024

Okay will try this fix, but not both ends of the socket are TX. one is TX, and the other are RX, but the thing is that Tx and Rx ends are on the same PC device, would that be an issue?

from 42.

ericstoneking avatar ericstoneking commented on August 17, 2024

No, both ends of the socket can be on the same device with no problem. You have run the TxRx example problem, right?

from 42.

mhmodayman avatar mhmodayman commented on August 17, 2024

Yes I tried TxRx example, and it works

Here is the new configuration for Inp_IPC of Tx, but still the same issue with Python being the Rx side.

<<<<<<<<<<<<<<< 42: InterProcess Comm Configuration File >>>>>>>>>>>>>>>>
1                                       ! Number of Sockets
**********************************  IPC 0   *****************************
TX                                      ! IPC Mode (OFF,TX,RX,TXRX,ACS,WRITEFILE,READFILE)
0                                       ! AC.ID for ACS mode
"State00.42"                            ! File name for WRITE or READ
SERVER                                  ! Socket Role (SERVER,CLIENT,GMSEC_CLIENT)
localhost     10001                     ! Server Host Name, Port 
TRUE                                    ! Allow Blocking (i.e. wait on RX)
TRUE                                    ! Echo to stdout
1                                       ! Number of TX prefixes
"SC"                                    ! Prefix 0

And here is the python code

import socket

client_port = 10001
client_host = "127.0.0.1"
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.settimeout(10)
client_socket.bind((client_host, client_port))

read_bytes, read_address = client_socket.recvfrom(1)  # buffer size is 1024 bytes
read_byte = read_bytes

client_socket.close()

And this is the error I get

OSError: [Errno 98] Address already in use

The error mentions that address 127.0.0.1 is already in use by Tx, but I think this is the case with TxRx example that both server and client are bound to same address and port, correct?

from 42.

ericstoneking avatar ericstoneking commented on August 17, 2024

Hi Mahmoud,

Yes I tried TxRx example, and it works

Okay, good. I was confused by your question about both ends of the socket being on the same machine. The TxRx problem demonstrates that.

I can't help you troubleshoot your python code. What I can suggest is that you start with TxRx, then replace the Rx end with your code. Configure your end as much like Rx as you can. See 42ipc.c, Kit/Source/iokit.c, and Source/IPC/*.c for details. Once you get that interface working, the rest is easy ;-)

Happy coding,
-Eric (he/him)

from 42.

mhmodayman avatar mhmodayman commented on August 17, 2024

Okay sure.

Meanwhile, could you please confirm the following configuration for the TxRx example?

Tx:

  • it is the socket server
  • its host is 127.0.0.1
  • its port is 10001

Rx:

  • it is the socket client
  • its host is 127.0.0.1
  • its port is 10001

Correct?

from 42.

mhmodayman avatar mhmodayman commented on August 17, 2024

It is working now

I had to replace this line: client_socket.bind((client_host, client_port))
with this: client_socket.connect((client_host, client_port))

import socket

client_port = 10001
client_host = "127.0.0.1"
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM , 0)  # AF_INET: IPv4, SOCK_DGRAM: UDP, SOCK_STREAM: TCP
client_socket.setblocking(False)
client_socket.settimeout(10)
client_socket.connect((client_host, client_port))

try:
    read_bytes = client_socket.recv(1)
except socket.timeout:
    print('WARNING Timedout on receiving bytes from ethernet')
except OSError:
    print('Server not connected yet')

client_socket.close()

from 42.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.