Open mhmodayman opened 1 year ago
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
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?
No, both ends of the socket can be on the same device with no problem. You have run the TxRx example problem, right?
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?
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)
Okay sure.
Meanwhile, could you please confirm the following configuration for the TxRx example?
Tx:
Rx:
Correct?
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()
I am trying to receive data from Tx using a python script as the Rx (both on the same device)
Here is the code for Rx, I wrote a code that greps over available ports It can grep over all ports except for 10001, and 44387
I am not sure how to receive from Tx, am I doing something wrong?
This is the configuration for Tx