Skip to content

Commit

Permalink
change port number
Browse files Browse the repository at this point in the history
  • Loading branch information
AliA5y committed Oct 27, 2024
1 parent d30a395 commit ca6ac0c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lib/components/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ const InputDecoration inputDecoration = InputDecoration(
),
),
);

const int portNumbr = 8089;
10 changes: 6 additions & 4 deletions lib/services/photon_receiver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:hive/hive.dart';
import 'package:photon/components/constants.dart';
import 'package:photon/methods/methods.dart';
import 'package:photon/models/sender_model.dart';
import 'package:photon/services/file_services.dart';
Expand Down Expand Up @@ -69,7 +70,8 @@ class PhotonReceiver {
for (int i = 1; i < 255; i++) {
//scan all of the wireless interfaces available
for (String netAddress in netAddresses) {
Future<Map<String, dynamic>> res = _connect('$netAddress.$i', 4040);
Future<Map<String, dynamic>> res =
_connect('$netAddress.$i', portNumbr);
list.add(res);
}
}
Expand Down Expand Up @@ -108,7 +110,7 @@ class PhotonReceiver {
static sendBackReceiverRealtimeData(SenderModel senderModel,
{fileIndex = -1, isCompleted = true}) {
http.post(
Uri.parse('http://${senderModel.ip}:4040/receiver-data'),
Uri.parse('http://${senderModel.ip}:$portNumbr/receiver-data'),
headers: {
"receiverID": id.toString(),
"os": Platform.operatingSystem,
Expand All @@ -122,7 +124,7 @@ class PhotonReceiver {
static receiveText(SenderModel senderModel, int secretCode) async {
RawTextController getInstance = GetIt.instance.get<RawTextController>();
var resp =
await Dio().get("http://${senderModel.ip}:4040/$secretCode/text");
await Dio().get("http://${senderModel.ip}:$portNumbr/$secretCode/text");
String text = jsonDecode(resp.data)['raw_text'];
getInstance.rawText.value = text;
}
Expand Down Expand Up @@ -205,7 +207,7 @@ class PhotonReceiver {

getInstance.fileStatus[fileIndex].value = "downloading";
await dio.download(
'http://${senderModel.ip}:4040/$_secretCode/$fileIndex',
'http://${senderModel.ip}:$portNumbr/$_secretCode/$fileIndex',
savePath,
deleteOnError: true,
cancelToken: getInstance.cancelTokenList[fileIndex],
Expand Down
19 changes: 10 additions & 9 deletions lib/services/photon_sender.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:photon/components/constants.dart';
import 'package:photon/methods/methods.dart';
import 'package:photon/models/file_model.dart';
import 'package:photon/models/sender_model.dart';
Expand Down Expand Up @@ -103,7 +104,7 @@ class PhotonSender {
List<String> deviceIps = (await getIP()).reversed.toList();
for (final deviceIp in deviceIps) {
try {
final tempServer = await HttpServer.bind(deviceIp, 4040);
final tempServer = await HttpServer.bind(deviceIp, portNumbr);
_server = tempServer;
_address = deviceIp;
log('succeess: $deviceIp');
Expand Down Expand Up @@ -131,15 +132,15 @@ class PhotonSender {
}

bool? allowRequest;
photonURL = 'http://$_address:4040/photon-server';
photonURL = 'http://$_address:$portNumbr/photon-server';
_server.listen(
(HttpRequest request) async {
if (request.requestedUri.toString() ==
'http://$_address:4040/photon-server') {
'http://$_address:$portNumbr/photon-server') {
request.response.write(jsonEncode(serverInf));
request.response.close();
} else if (request.requestedUri.toString() ==
'http://$_address:4040/get-code') {
'http://$_address:$portNumbr/get-code') {
String os = (request.headers['os']![0]);
String username = request.headers['receiver-name']![0];
allowRequest = await senderRequestDialog(username, os);
Expand All @@ -158,16 +159,16 @@ class PhotonSender {
request.response.close();
}
} else if (request.requestedUri.toString() ==
'http://$_address:4040/getpaths') {
'http://$_address:$portNumbr/getpaths') {
request.response
.write(jsonEncode({'paths': fileList, 'isApk': isApk}));

request.response.close();
} else if (request.requestedUri.toString() ==
'http://$_address:4040/favicon.ico') {
'http://$_address:$portNumbr/favicon.ico') {
request.response.close();
} else if (request.requestedUri.toString() ==
"http://$_address:4040/receiver-data") {
"http://$_address:$portNumbr/receiver-data") {
//process receiver data
processReceiversData({
"os": request.headers['os']!.first,
Expand All @@ -186,12 +187,12 @@ class PhotonSender {
"isCompleted": request.headers['isCompleted']!.first
});
} else if (request.requestedUri.toString() ==
"http://$_address:4040/$_randomSecretCode/data/type") {
"http://$_address:$portNumbr/$_randomSecretCode/data/type") {
request.response
.write(jsonEncode({"type": isRawText ? "raw_text" : "file"}));
request.response.close();
} else if (request.requestedUri.toString() ==
"http://$_address:4040/$_randomSecretCode/text") {
"http://$_address:$portNumbr/$_randomSecretCode/text") {
request.response.write(jsonEncode({"raw_text": _rawText}));
request.response.close();
} else {
Expand Down

0 comments on commit ca6ac0c

Please sign in to comment.