Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Socket programming help

So im programming a client/server setup in C, everything has compiled fine, and my issue here is 2 things :

1. initially, i first have the client tell me to enter a message that is supposed to go to the server, i enter a message and get hit with a "Segmentation Fault : 11"

2. After i get hit with the segmentation fault, the server tells me to enter a message, to send to the client, when i do that i get " Bus error : 10"

In order to summarize
Client error : "Segmentation Fault : 11"

Server error : "Bus error : 10"


client(https://pastebin.com/7Xr7Hcq5)
server(https://pastebin.com/vNLLUSPV)
my nice person u gotta allocate memory for that message
I find it hilarious no one on HF could produce a half decent client/server code
(Jun 10, 2019 08:28 AM)YouthInAsia Wrote:  I find it hilarious no one on HF could produce a half decent client/server code

*In this Section only. You do know this section is for people who want to talk about C/C++ Code, Errors and stuff.
(Jun 10, 2019 08:39 AM)lynxmk Wrote:  *In this Section only. You do know this section is for people who want to talk about C/C++ Code, Errors and stuff.

Yes but you'd expect people to HAVE AT LEAST A BASIC UNDERSTANDING OF ANY FORM OF NETWORKING / CODE
I fixed your client. It was a simple error. You were taking input in a pointer instead of an char array, I think.
client.c (Click to View)

I looked at the server code but I don't understand what you're trying to create or do. But it looks like you're sending from both sides at the same time and receiving at the same time.
If the server side sends some data, Then the client must receive it. But, Look here; And tell me do you see what I mean?
upload.ee/image/10076060/Screenshot_2019-06-10_20-43-49.png
(Jun 10, 2019 09:12 AM)lynxmk Wrote:  I fixed your client. It was a simple error. You were taking input in a pointer instead of an char array, I think.
client.c (Click to View)

I looked at the server code but I don't understand what you're trying to create or do. But it looks like you're sending from both sides at the same time and receiving at the same time.
If the server side sends some data, Then the client must receive it. But, Look here; And tell me do you see what I mean?
upload.ee/image/10076060/Screenshot_2019-06-10_20-43-49.png

Yeah i think so, the problem may be i have some code on the server side that should be on the client side, either that or it had to do with the message char.
(Jun 10, 2019 01:53 PM)Truth3356 Wrote:  Yeah i think so, the problem may be i have some code on the server side that should be on the client side, either that or it had to do with  the message char.

Read my first post, you weren't allocating memory. You could use a pointer, but you'd have to dynamically allocate memory for that pointer. That pointer is just a variable, it literally points to garbage, whatever is at the stack at that time. Hence the segmentation fault.
(Jun 10, 2019 04:15 PM)doxerhacker Wrote:  Read my first post, you weren't allocating memory. You could use a pointer, but you'd have to dynamically allocate memory for that pointer. That pointer is just a variable, it literally points to garbage, whatever is at the stack at that time. Hence the segmentation fault.

Okay, i will fix that, thanks man.


(Jun 10, 2019 08:28 AM)YouthInAsia Wrote:  I find it hilarious no one on HF could produce a half decent client/server code

You gotta give me credit for at least trying.
LOOOL. hahahaha fu*ki*g shitty code. "i don't know how to code so I will ask on Hackforums what is wrong with my copy-pasted code". I mean i came here thinking you were going to ask a specific question related to implementing something from RFC docs or something else along this line which would be no problem)), instead you gave me a laugh hahahaha
(Jun 13, 2019 08:07 AM)MaximumPain Wrote:  LOOOL. hahahaha fu*ki*g shitty code. "i don't know how to code so I will ask on Hackforums what is wrong with my copy-pasted code". I mean i came here thinking you were going to ask a specific question related to implementing something from RFC docs or something else along this line which would be no problem)), instead you gave me a laugh hahahaha

Instead of motherfuckin helping, you shitposted and made fun of OP? I dare you post some code you written on your first day of coding. duh.
(Jun 13, 2019 08:46 AM)dracx Wrote:  Instead of motherfuckin helping, you shitposted and made fun of OP? I dare you post some code you written on your first day of coding. duh.

Dont worry, i fixed it, it works now.


(Jun 13, 2019 08:07 AM)MaximumPain Wrote:  LOOOL. hahahaha fu*ki*g shitty code. "i don't know how to code so I will ask on Hackforums what is wrong with my copy-pasted code". I mean i came here thinking you were going to ask a specific question related to implementing something from RFC docs or something else along this line which would be no problem)), instead you gave me a laugh hahahaha

Theres zero wrong with asking for help. I didn't ask anyone to just do the whole thing for me. I never asked to have my hand held through it. I had a question, and i self-advocated and asked for help.
I don't know if you have fixed your problem. However, a quick glance through the code revealed one telling problem. In the client, you declare char*message but never allocate a buffer (new char[size_of_buffer]). If memory serves correctly, scanf requires a buffer not a pointer to null (which is what you pass in your case).

Hope this 'points' you in the right direction.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by LilDeepWebJan 29, 2022 10:06 AM 3 228 Jan 29, 2022 10:06 AM
Last Post: yuumi
[C] by mafiaboySep 6, 2019 11:37 AM 13 441 Sep 6, 2019 11:37 AM
Last Post: zp_city
[C] by Truth3356Jun 2, 2019 10:02 PM 6 176 Jun 2, 2019 10:02 PM
Last Post: Truth3356