Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: null is not an object (evaluating 'Sockets.listen') #161

Closed
EsioFreitas opened this issue Sep 21, 2022 · 1 comment
Closed

TypeError: null is not an object (evaluating 'Sockets.listen') #161

EsioFreitas opened this issue Sep 21, 2022 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request is duplicated

Comments

@EsioFreitas
Copy link

EsioFreitas commented Sep 21, 2022

Message

Hello. I put the server example in the code and it is giving an error. Could you please help me?

Code:

import React, { useEffect, useRef } from "react";

import { View, Text, ImageBackground } from "react-native";
import Button from "../../components/button";
import splashImg from "../../assets/splash.png";
import { useDispatch, useSelector } from "react-redux";
import { getUserInfo } from "../../store/Identity/Authenticate/selectors";
import { fetchUser } from "../../store/Identity/Authenticate/thunks";
import { AppRoutes } from "../../navigation/routes";
import TcpSocket from "react-native-tcp-socket";

const LoginPage = ({ navigation }) => {
  const server = TcpSocket.createServer(function (socket) {
    socket.on("data", (data) => {
      socket.write("Echo server " + data);
    });

    socket.on("error", (error) => {
      console.log("An error ocurred with client socket ", error);
    });

    socket.on("close", (error) => {
      console.log("Closed connection with ", socket.address());
    });
  }).listen({ port: 12345, host: "0.0.0.0" });

  server.on("error", (error) => {
    console.log("An error ocurred with the server", error);
  });

  server.on("close", () => {
    console.log("Server closed connection");
  });
  return (
    <View style={{ flex: 1 }}>
      <ImageBackground
        style={{
          flex: 1,
          justifyContent: "flex-end",
          alignItems: "center",
        }}
        source={splashImg}
        resizeMode="cover"
      >
        <View style={{ width: "50%", marginBottom: 100 }}>
          <Button
            title="Entrar"
            onPress={() => navigation.navigate(AppRoutes.filterPage)}
            type="secondary"
          />
        </View>
      </ImageBackground>
    </View>
  );
};

export default LoginPage;

Error

image

@EsioFreitas EsioFreitas added the bug Something isn't working label Sep 21, 2022
@Rapsssito
Copy link
Owner

@EsioFreitas, I believe your issue is related to #122, #103 and #27. Please, take a look at #103 for a list of possible fixes.

@Rapsssito Rapsssito added the duplicate This issue or pull request is duplicated label Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request is duplicated
Projects
None yet
Development

No branches or pull requests

2 participants