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

Can't send TCP packages #88

Open
FunctionEurus opened this issue May 1, 2024 · 0 comments
Open

Can't send TCP packages #88

FunctionEurus opened this issue May 1, 2024 · 0 comments

Comments

@FunctionEurus
Copy link

FunctionEurus commented May 1, 2024

Hi, I'm trying to use raw socket to make TCP connections and send HTTP GET requests, but honestly I'm a totally beginner of network programming so I met some problems when coding.
In README.md, send() function is declared as socket.send (buffer, offset, length, address, beforeCallback, afterCallback) , but when I print the req in onSendReady(), the real object is this:

{
  buffer: <Buffer 68 65 6c 6c 6f>,
  offset: 0,
  length: 5,
  address: '155.138.142.54',
  afterCallback: [Function (anonymous)],
  beforeCallback: null
}

So the before callback and the after callback seems to be placed in wrong place? I'm not sure whether this is the source of my problem, because the error message is made up of some mojibake:

Error sending packet: Error: �ṩ��һ����Ч�IJ�����

    at Socket.onSendReady (C:\Users\funct\Desktop\node-socket\node_modules\raw-socket\index.js:102:14)
    at SocketWrap.emit (node:events:518:28)

And here is my code, thanks for your reading.

const raw = require("raw-socket");

const socket = raw.createSocket({
  protocol: raw.Protocol.TCP,
});

socket.send(
  Buffer.from("hello"),
  0,
  Buffer.from("hello").length,
  "155.138.142.54",

  (err, bytes) => {
    if (err) {
      console.error("Error sending packet:", err);
    } else {
      console.log("Packet sent successfully", bytes);
    }
  }
);

PS: when I added another function(() => {console.log("ready");}) as the fifth parameter, the error message disappeared and Packet sent successfully undefined was printed in the console. However I just couldn't catch that package in wireshark, so this was another failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant