Skip to content
Advertisement

SEGFAULT after recv from socket

I have next trouble: after receiving data from sockets, server app generates segfault and shutdown. Code of client and server side are below.

server:

JavaScript

Client:

JavaScript

In other words, client connected successfully. But after sending message, server generate segm fault error. What went wrong?

Advertisement

Answer

When running the code it seg faults at:

JavaScript

Package is a struct with two members nick and buff. Then you read the socket with the size of PACKAGE struct which is size 16. I guess this is not really what you want. Maybe you could specify nick and buff as fixed length char arrays.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement