AmmosSource
guix
Last change
on this file since b67e7e5 was b67e7e5, checked in by recknagel <recknagel@…>, 3 years ago |
added closing of sockets
|
-
Property mode
set to
100644
|
File size:
690 bytes
|
Line | |
---|
1 | import sys
|
---|
2 | import os
|
---|
3 | sys.path.append('../src/')
|
---|
4 | import socket
|
---|
5 |
|
---|
6 | try:
|
---|
7 | file_path = sys.argv[1]
|
---|
8 | except IndexError:
|
---|
9 | print("Please provide a file path as argument")
|
---|
10 | sys.exit(1)
|
---|
11 | except FileNotFoundError:
|
---|
12 | print("File not found")
|
---|
13 | sys.exit(1)
|
---|
14 |
|
---|
15 | file = open(file_path, 'rb')
|
---|
16 | total_bytes = file.read()
|
---|
17 | print('File read')
|
---|
18 |
|
---|
19 | print('Connecting to socket')
|
---|
20 | out_socket = socket.socket()
|
---|
21 | out_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
---|
22 | out_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
---|
23 | out_socket.connect(('127.0.0.1', 12345))
|
---|
24 | print('Connected')
|
---|
25 | print('Sending Bytes')
|
---|
26 | out_socket.sendall(total_bytes)
|
---|
27 | out_socket.close()
|
---|
28 | out_socket.shutdown(socket.SHUT_RDWR)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.