Why doesnt this code work???? it just stops at the socket() and does not
print HI.
why is this?
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define MYPORT 3490
int main()
{
int socket_id, newsocket;
int listen_return;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
socket_id =socket(AF_INET, SOCK_STREAM, 0); <--------- here god
damn it
printf("HI");
my_addr.sin_family = AF_INET;
my_addr.sin_port=htons(MYPORT);
my_addr.sin_addr.s_addr=INADDR_ANY;
memset(&(my_addr.sin_zero), '\0',8);
bind(socket_id, (struct sockaddr *)&my_addr,sizeof(struct sockaddr));
while(0==0)
{
if(listen(socket_id, 10)==0)
{
printf("Connected");
newsocket=accept(socket_id, (struct sockaddr*)&their_addr,
sizeof(struct sockaddr_in));
}
else
{
printf("not connected");
}
};
return 0;
} 2 1191
"Robert Smith" <la******@yahoo.com> wrote in
news:wA*******************@twister.nyroc.rr.com: Why doesnt this code work???? it just stops at the socket() and does not print HI. why is this?
Um... there's nothing C++-specific in here... it's all stock C. (OK,
ignoring that all the BSD stuff isn't Standard....)
Anyway, your problem is most likely the buffered output of printf. You
might want to try sticking "\n" at the end of your printf string
literals.
#include <stdio.h>
Deprecated, use <cstdio>
#include <stdlib.h>
Deprecated, use <cstdlib>
#include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h>
All non-standard....
#define MYPORT 3490
int main()
Good for you... someone who does use a Standard main() :)
{ int socket_id, newsocket; int listen_return; struct sockaddr_in my_addr; struct sockaddr_in their_addr;
socket_id =socket(AF_INET, SOCK_STREAM, 0); <--------- here god damn it printf("HI"); my_addr.sin_family = AF_INET; my_addr.sin_port=htons(MYPORT); my_addr.sin_addr.s_addr=INADDR_ANY; memset(&(my_addr.sin_zero), '\0',8);
bind(socket_id, (struct sockaddr *)&my_addr,sizeof(struct sockaddr));
You might want to check the return value of bind.... you may not be able
to get the port....
while(0==0)
What's wrong with "while(true)". IMHO: it's clearer... I briefly
thought: "while false? huh? Oh wait, he's comparing 0 to 0.. that's
while true."
{
if(listen(socket_id, 10)==0)
Your program is probably getting to this listen statement, and then
blocks until it gets a connection. But since none of the printfs caused
the buffer to be flushed, you probably aren't getting any output....
{ printf("Connected"); newsocket=accept(socket_id, (struct sockaddr*)&their_addr, sizeof(struct sockaddr_in));
} else { printf("not connected"); }
};
return 0; }
Robert Smith <la******@yahoo.com> spoke thus: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h>
It appears you can benefit from the following: http://www.slack.net/~shiva/welcome.txt http://www.parashift.com/c++-faq-lite/
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: cricketunes |
last post by:
Hi folks,
this one's had me stumped!
$conn=ora_logon("cricketunes@pickles","j8j3kf");
if ($conn != TRUE)
die("Unable to connect to oracle, exiting...\n");
$cursor = ora_open($conn);
if...
|
by: Chris Geerdink |
last post by:
combo with PHP. what is wrong with the Javascript?
else
{
include("mysql.php");
$query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES
('".$_POST."', '".$_POST."',...
|
by: asdf |
last post by:
Hello!
Can someone tell me whats wrong with this piece of code:
Option Compare Database
Option Explicit
Sub retrieve()
Dim rst As ADODB.Recordset
Dim i As Integer
|
by: Tony |
last post by:
I found similar code for encoding/decoding strings in VB which works fine.
However I wanted to use it in a C# projected and can't get it to work.
When it executes the TransformFinalBlock() call at...
|
by: **Developer** |
last post by:
If e.Button = MouseButtons.Left Then
also from a
Dim Answer As DialogResult = MessageBox.Show..
Select Case Answer
Case DialogResult.Yes
| |
by: Mike Barnard |
last post by:
It's a simple test... VERY SIMPLE. But...
In an external stlyesheet some attributes don't show. With the same
styles cut and pasted to the test internally it works as expected.
Anyone tell...
|
by: LoneHunter01 |
last post by:
Basically, I just need a general direction on where to go for this. Yes, this is for a school project, though it's strictly an optional one (and I have tried many solutions, one in-depth). We've...
|
by: islayer |
last post by:
can someone tell me what is wrong with the bold code? i am just learning perl. the program should create a perl file with a random name (5 letters, followed by a number), but the name is always just...
|
by: Muzammil |
last post by:
whats the beauty of "malloc" over "new" why its helpful for
programmer.for its own memory area.??
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |