GithubHelp home page GithubHelp logo

Comments (4)

Rapsssito avatar Rapsssito commented on May 16, 2024 1

Currently there is no possibility for reusable address. Sorry about that.

from react-native-tcp-socket.

matheusmorett2 avatar matheusmorett2 commented on May 16, 2024

Maybe i can help you with this issue. How do you recreate the socket connection?

from react-native-tcp-socket.

Rapsssito avatar Rapsssito commented on May 16, 2024

@matheusmorett2 feel free to open a PR with this feature! Look at the Obj-C and Java code for more information about the socket creation.

public TcpSocketClient(final TcpReceiverTask.OnDataReceivedListener receiverListener, final Integer id,
final String address, final Integer port, final String localAddress, final int localPort, final Network network)
throws IOException {
this.id = id;
// Get the addresses
InetAddress localInetAddress = InetAddress.getByName(localAddress);
InetAddress remoteInetAddress = InetAddress.getByName(address);
// Create the socket
socket = new Socket();
if (network != null)
network.bindSocket(socket);
socket.setReuseAddress(true);
socket.bind(new InetSocketAddress(localInetAddress, localPort));
socket.connect(new InetSocketAddress(remoteInetAddress, port));
receiverTask = new TcpReceiverTask();
receiverTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Pair<>(this, receiverListener));
}

- (BOOL)connect:(NSString *)host port:(int)port withOptions:(NSDictionary *)options error:(NSError **)error
{
if (_tcpSocket) {
if (error) {
*error = [self badInvocationError:@"this client's socket is already connected"];
}
return false;
}
_tcpSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:[self methodQueue]];
[_tcpSocket setUserData: _id];
BOOL result = false;
NSString *localAddress = (options?options[@"localAddress"]:nil);
NSNumber *localPort = (options?options[@"localPort"]:nil);
if (!localAddress && !localPort) {
result = [_tcpSocket connectToHost:host onPort:port error:error];
} else {
NSMutableArray *interface = [NSMutableArray arrayWithCapacity:2];
[interface addObject: localAddress?localAddress:@""];
if (localPort) {
[interface addObject:[localPort stringValue]];
}
result = [_tcpSocket connectToHost:host
onPort:port
viaInterface:[interface componentsJoinedByString:@":"]
withTimeout:-1
error:error];
}
return result;
}

from react-native-tcp-socket.

Rapsssito avatar Rapsssito commented on May 16, 2024

@matheusmorett2, I have created a PR (#17) for this feature. Feel free to contribute there!

from react-native-tcp-socket.

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.