473,787 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Call For Help

I had developed the client program under Visual C++ 6.0. I use the
Windows socket programming. I compile and build my program using the
Win32 Console application.The re is no errors and warnings. But after
I executing the program, I found that if(argc < 3) {
printf("usage: %s <server> <data1> <data2> ...
<dataN>\n",ar gv[0]);
exit(1);
}

the output is <server> <data1> <data2> ...
<dataN> and stop with executing the rest of the program.My work
is to send data to the server PC which is under the Linux
environment.

The following is my program:Thanks for helping.

#include <stdio.h>
#include <winsock2.h>
#include <windows.h>
#define SERVER_PORT 1500
#define MAX_MSG 100

//int CreatFile(char *szServer, short nPort);

//*CreatFile();

int main (int argc, char *argv[]) {
WORD wVersionRequest ed = MAKEWORD(1,1);
WSADATA wsaData;
int nRet;

//
// Initialize WinSock and check the version
//
nRet = WSAStartup(wVer sionRequested, &wsaData);
if (wsaData.wVersi on != wVersionRequest ed)
{
fprintf(stderr, "\n Wrong version\n");
return 0;
}
int sd, rc, i;
struct sockaddr_in localAddr, servAddr;
struct hostent *h;

if(argc < 3) {
printf("usage: %s <server> <data1> <data2> ...
<dataN>\n",ar gv[0]);
exit(1);
}
// The gethostbyname() function is used when we have the DNS name
of our server
h = gethostbyname(a rgv[1]);
if(h==NULL) {
printf("%s: unknown host '%s'\n",argv[0],argv[1]);
exit(1);
}

//
// Fill in the address structure
//

servAddr.sin_fa mily = h->h_addrtype;
memcpy((char *) &servAddr.sin_a ddr.s_addr, h->h_addr_list[0],
h->h_length);
servAddr.sin_po rt = htons(SERVER_PO RT);

/* create socket */
sd = socket(AF_INET, SOCK_STREAM, 0);
if(sd<0) {
perror("cannot open socket ");
exit(1);
}

/* bind any port number */
localAddr.sin_f amily = AF_INET;
localAddr.sin_a ddr.s_addr = htonl(INADDR_AN Y);
localAddr.sin_p ort = htons(0);

rc = bind(sd, (struct sockaddr *) &localAddr,
sizeof(localAdd r));
if(rc<0) {
printf("%s: cannot bind port TCP %u\n",argv[0],SERVER_PORT);
perror("error ");
exit(1);
}

/* connect to server */
rc = connect(sd, (struct sockaddr *) &servAddr,
sizeof(servAddr ));
if(rc<0) {
perror("cannot connect ");
exit(1);
}

for(i=2;i<argc; i++){

rc = send(sd, argv, strlen(argv[i]) + 1, 0);

if(rc<0) {
perror("cannot send data ");
closesocket(sd) ;
exit(1);

}

printf("%s: data%u sent (%s)\n",argv[0],i-1,argv[i]);
}
//CreatFile(argv[1], SERVER_PORT);
//*CreatFile();

// Release WinSock
//
WSACleanup();
return 0;

}
*---------------------------------*
Posted at: http://www.GroupSrv.com
Check: http://wwww.HotCodecs.com
*---------------------------------*

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 17 '05 #1
0 948

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5294
by: Greg Chapman | last post by:
I am at my wit's end trying to get information out of Streamline.net's support dept about my problem. They reply quickly enough, but seem to try and give out the least possible amount of info each time. The transcript so far is reproduced for your amusement below. To summarise: I've put up a Sudoku-solving program called Sudoku.exe. I want to call it in a php script to solve a puzzle and output the solution. It works fine with...
4
3396
by: mangi03 | last post by:
Hi, I came acrosss g++ compile errors whenever I make a function call by reference and found out from the test program that compiler is treating the function argument differently when another function call funcRet()is made which returns the expected argument type for the function call by reference funcByRef(class A&); The only way to get around this probelm is to first call the funcRet(), assign its value to a variable and pass that...
5
1434
by: Anand Ganesh | last post by:
Hi All, I need some help. I am sort of not sure how to approach this problem. I have a MAINPROGRAM. This is the core application. I have asked two of my staff to developed two different Windows Controls. Say ControlA.dll and ControlB.dll. As usual I know how to add these .dlls as the reference and then start using
4
1871
by: ruca | last post by:
Hi, Can anyone tell me how can I call a function of my Web Page from javascritp???? I have a grid that when I click in a cell I want to call another function present in that same page? It is possible to do that?
4
3909
by: abcd | last post by:
I am novice asp.net programmer. I have xyz.js file which has resuable functions. I have asp.net form abcd.aspx and the code behind file abcd.aspx.cs, I want to put a 'Help' button when clicked it will open a window and open the required file for me. I am have issues 1.I tried calling my xyz.js function i.e. ShowHelp in the call like in my
5
6543
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly new to VB.NET, so I need some help. Here is a code snippit :
5
2318
by: SStory | last post by:
Hi all, I really needed to get the icons associated with each file that I want to show in a listview. I used the follow modified code sniplets found on the internet. I have left in commented code for anyone else who may be looking to do the same.
7
6807
by: archana | last post by:
Hi all, I am having application in which i am doing asynchronous call.I am using manualresetevent to wait for asynchronous call to complete. I want to stop asynchronous call after certain period of time. I want something like thread.abort for aborting aynchronous call. Can someone tell me way of aborting asynchronous call.
11
11536
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the function whether i click the link then i tried this (using forms)
2
7577
by: Michael George Lerner | last post by:
Hi, (Python 2.5, OS X 10.4.10) I have a program called pdb2pqr on my system. It is installed so that "pdb2pqr" is in my path and looks like: #\!/bin/zsh -f /sw/share/pdb2pqr/pdb2pqr.py "$@" When I call it via this script:
0
9655
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10169
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.