Hello I am new in networking field and using socket in Python I am trying to access the function frame_reception_function() but I am getting error "OSError: [Errno 98] Address already in use" In forward_send_received(), I am calling four different functions using thread, because in my work, this node can be received request frame form previous node and also need to forward this frame to next node and it is also receiving data frame form next node and send to the previous node. so it received two from two sides. How it is possible to access the same socket. I am also closing the connection but it does not work. Can anybody help me to remove the above error (Address already in Used)
def frame_reception_function ():
print ("starting of frame reception")
PORT = 12345
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(('',PORT))
s.listen(1)
conn,address=s.accept()
message=conn.recv(1024).decode()
conn.close()
recv_message=message.split(';')
message_type=recv_message[0]
if (received_message=='req_status'):
print ('Received Message is req_status')
previous_ip=recv_message[1]
return message_type,previous_ip,recv_message
else:
print ("received message is :",received_message)
print ("Received from:",recv_message[4])
ip=recv_message[4]
#cmd = "arp -n " + str(ip) + " | awk '/" + str(ip) + "/{print $3}'" # Can we extract MAC address from IP instead of Broadcast address???
#x = os.popen(cmd).read().strip()
return recv_message[0],ip,recv_message
def forward_send_received():
Frame_type,ip_address,received_message=frame_reception_function ()
print ("after while")
print (Frame_type)
print (Frame_SrcAddr)
print (ip_address)
print (received_message)
if (Frame_type=="req_status"):
if (not Req_Frame_Relayed): # Check Req_Frame_status
forward_req_status_frame()
Req_Frame_Relayed=True
Probabilistic_Reliable_Broadcast(Frame_type)
Send_Data_status_frame()
Probabilistic_Reliable_Broadcast("current_node_data")
else:
if (Frame_SrcAddr not in Resp_forwarded_set):
Resp_forwarded_set()
forward_Data_status_frame(received_message)
Resp_number=Resp_number+1
Probabilistic_Reliable_Broadcast(Frame_type)
while (time.time()-start_time<Status_collecting_time_interval) and (Resp_number<Nmax):
print ("starting of while ")
Thread(target=forward_send_received).start()