LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2022, 07:26 AM   #1
nather
LQ Newbie
 
Registered: Nov 2022
Posts: 5
Blog Entries: 1

Rep: Reputation: 0
C program Socket connect method


Greetings All,

I am using C program Socket connect method. The method return either 0 or - 1 but some time could not return anything and i could not trace. How i can solve the problem. Please advice.


connect(socket, (struct sockaddr *)addr, sizeof(*addr));

Thanks
nather
 
Old 11-02-2022, 07:28 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 19,248

Rep: Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525Reputation: 6525
add a timeout
 
3 members found this post helpful.
Old 11-05-2022, 03:49 AM   #3
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 565

Rep: Reputation: 288Reputation: 288Reputation: 288
Hi,

You need proper error handling. There are functions such as perror() and strerror() which can help in diagnosis. More information using the man pages:
Code:
man 3 perror
Or get the man pages online, if you're not on Linux.

I learnt network programming from scratch using https://beej.us/guide/bgnet/. There are good examples in there.

All the best.
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify UDP receive socket buffer size for an open socket (not at system level, but socket level) barz_83_LQ Linux - Networking 2 11-27-2017 08:56 PM
Connecting client socket to server socket only once in socket programming srinietrx Programming 5 08-20-2017 12:53 PM
Error (Cannot connect to unix socket '/var/lib/clamav/clamd.socket': connect: No such file or directory) Toadman Ubuntu 1 08-10-2016 07:00 PM
program to listen on TCP socket and start some program with I/O redirected to socket leniviy Linux - Software 4 08-12-2013 06:51 AM
connect: socket operation on non-socket bit7 Linux - Networking 0 02-18-2003 06:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration