Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-16-2008, 05:58 AM
bodhi2016 bodhi2016 is offline
Newbie
 
Join Date: Jan 2008
Posts: 29
Rep Power: 3
bodhi2016 is on a distinguished road
Default Network Question For Beginners

Guys i am trying to learn the winsock programing from these two sites
Winsock Networking Tutorial (C++) - MadWizard.org
C/C++ Winsock Tutorial - by Mulciber

One thing that both the second tutorial is saying is that the
"When you're writing the code presented in this tutorial, make
sure that ***libwsock32*** is linked"
What is this linking and how should i link it with my programme .
And if i want to make a winsock programme the connection should
be between the server and a client .Suppose if i want to make a
connection betwwen my computer and my fathers laptop -can that be made or
before that i have to change my computer to a server by installing a software
like Apache or Personal Web Server(i may be wrong .
I have never used these softwares before .But as far as i know they make the
PC to act as a sever when i am connected to the net )and then make my fathers laptop act as a
client .Can anybody tell some more good tutorial for winsock programming
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-16-2008, 08:46 AM
MeTh0Dz MeTh0Dz is offline
SLICE OWNZ YOUR SOUL
 
Join Date: May 2008
Posts: 294
Last Blog:
Ternary Operator CPP
Rep Power: 0
MeTh0Dz has a spectacular aura aboutMeTh0Dz has a spectacular aura aboutMeTh0Dz has a spectacular aura about
Default Re: Network Question For Beginners

First off what IDE are you using? It's different linking in each one. Also when you write client/server software the whole idea is that you are writing the software that is going to communicate. It doesn't need to be running on a designated server or client box, you are writing the software that will make the box run as a client or server. Therefore you can just put some server software that you write on your dad's box, and some client software on yours and you will be able to communicate. The simplest example to get started with is probably just an echo server.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-16-2008, 11:39 AM
bodhi2016 bodhi2016 is offline
Newbie
 
Join Date: Jan 2008
Posts: 29
Rep Power: 3
bodhi2016 is on a distinguished road
Default Re: Network Question For Beginners

Quote:
Originally Posted by MeTh0Dz View Post
First off what IDE are you using? It's different linking in each one. Also when you write client/server software the whole idea is that you are writing the software that is going to communicate. It doesn't need to be running on a designated server or client box, you are writing the software that will make the box run as a client or server. Therefore you can just put some server software that you write on your dad's box, and some client software on yours and you will be able to communicate. The simplest example to get started with is probably just an echo server.
Your rply was really helpful .I would like a little bit more help(amatuers like me are irritating aren't they??).Well i am using Dev c++ .What is an echo server .
You are telling that to write a server software on my own and put it into my fathers laptop.Can a amatuer coder like me write a server software .Its like making Apache of my own which has been created by world's great hacker .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-16-2008, 05:43 PM
MeTh0Dz MeTh0Dz is offline
SLICE OWNZ YOUR SOUL
 
Join Date: May 2008
Posts: 294
Last Blog:
Ternary Operator CPP
Rep Power: 0
MeTh0Dz has a spectacular aura aboutMeTh0Dz has a spectacular aura aboutMeTh0Dz has a spectacular aura about
Default Re: Network Question For Beginners

Ok..... In Dev-Cpp goto Project >> Project Options >> Parameters >> Add Library or Object...

An echo server is a server that a client can send a message to and the echo server will reply with the exact same message.

Server software is anything that can be requested for data from a client, Apache is obviously the extreme and you won't be writing that. But you can write simple server/client software. You just need to write applications that have the ability to communicate across a network, which is why I suggest starting with something easy like an echo server and client.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-18-2008, 10:59 AM
bodhi2016 bodhi2016 is offline
Newbie
 
Join Date: Jan 2008
Posts: 29
Rep Power: 3
bodhi2016 is on a distinguished road
Default Re: Network Question For Beginners

Win Connect
Code:
#include <windows.h> //Required for socket init
#include <iostream>
int main(){
char buf[256];
WSAData wsdata; //Declare WSAData
WORD wsver=MAKEWORD(2, 0); //We want Winsock 2.0
int nret=WSAStartup(wsver, &wsdata); //Pass version 2.0 and pointer to implement
if(nret != 0){ //Init failed
/*A successful return value should be 0 */
std::cout<<"Startup failed, error code: "<<WSAGetLastError(); //Returns error code
WSACleanup(); //Cleanup Winsock library
return -1;
}
std::cout<<"Init success\n";
SOCKET kSock=socket(AF_INET, SOCK_STREAM, 0);
if(kSock == INVALID_SOCKET){
std::cout<<"Socket init failed";
return -1;
}
std::cout<<"Socket initialized\n";
sockaddr_in sin;
sin.sin_port=htons(808); //Connect to port 80
sin.sin_addr.s_addr=inet_addr("127.0.0.1"); //Connect to localhost
sin.sin_family=AF_INET;
if(connect(kSock,(sockaddr*)&sin, sizeof(sin)) == SOCKET_ERROR){ //Check the condition
std::cout<<"Connect failed, error: "<<WSAGetLastError(); //Returns error code
WSACleanup(); //Cleanup the library
return -1;
}
std::cout<<"Connection successful!\n";
recv(kSock, buf, sizeof(buf), 0); //Receive "Hello" from server
std::cout << buf;
closesocket(kSock);
return 0;
}
Win Listen
Code:
#include <windows.h> //Required for socket init
#include <iostream>
int main(){
char buf[] = "Hello\n";
WSAData wsdata; //Declare WSAData
WORD wsver=MAKEWORD(2, 0); //We want Winsock 2.0
int nret=WSAStartup(wsver, &wsdata); //Pass version 2.0 and pointer to implement
if(nret != 0){ //Init failed
/*A successful return value should be 0 */
std::cout<<"Startup failed, error code: "<<WSAGetLastError(); //Returns error code
WSACleanup(); //Cleanup Winsock library
return -1;
}
std::cout<<"Init success\n";
SOCKET kSock=socket(AF_INET, SOCK_STREAM, 0);
if(kSock == INVALID_SOCKET){
std::cout<<"Socket init failed";
return -1;
}
std::cout<<"Socket initialized\n";
sockaddr_in sin;
sin.sin_port=htons(808);
sin.sin_addr.s_addr=INADDR_ANY;
sin.sin_family=AF_INET;
if(bind(kSock,(sockaddr*)&sin, sizeof(sin)) == SOCKET_ERROR){
std::cout<<"Failed to bind\n";
WSACleanup(); //Cleanup Winsock library
return -1;
}
std::cout<<"Bind successful!\n";
while (listen(kSock, SOMAXCONN) == SOCKET_ERROR); //Loop in order to constantly listen
/* set the number of connections to SOMAXCONN, in which case the provider chooses a reasonable value (5 in Windows XP
Professional) */
SOCKET client;
int len = sizeof(sin);
client=accept(kSock, (sockaddr*)&sin, &len);
std::cout<<"Connection established!\n";
send(client, buf, sizeof(buf), 0); //Send "Hello"
closesocket(client); //Close both socket handles
closesocket(kSock);
WSACleanup();
return 0;
}
Methodz i found an example of winsock programming on the net.I just wanted to verify from you .The portion of code Win Connect is the client software (which will go inside my my laptop)and the sceond portion Win Listen is the server software(which will go inside my fathers laptop). Is there anyway i can execute the both portion of code in my computer. This is a quote from the tutorial that i am reading.the line marked in red has made me ask you this question.
Quote:
In the part 1, we looked at initializing the library, creating sockets, making our own connections, and terminating the
library and our socket handle(s). Now it's time to look at all of this, but instead of connecting, we will be listening for
our own connections instead.
To do so, we need to bind our socket to a defined port, then use the listen() function to wait
for connections. To test whether or not our program succeeded, we can use the command prompt. netstat -ano (o for PID, n for
numerical output, and a for displaying listening ports/active connections) does the trick because we can refer to the PID of
our application using the task manager, then check whether or not the PID shows up in the output, along with the defined
port.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 06-18-2008, 01:50 PM
MeTh0Dz MeTh0Dz is offline
SLICE OWNZ YOUR SOUL
 
Join Date: May 2008
Posts: 294
Last Blog:
Ternary Operator CPP
Rep Power: 0
MeTh0Dz has a spectacular aura aboutMeTh0Dz has a spectacular aura aboutMeTh0Dz has a spectacular aura about
Default Re: Network Question For Beginners

Okay, I didn't really look through the code because it pains me to read **** that isn't indented. I realize you didn't write it, but it hurts my eyes. And yes, there is a way you can run it on your on computer. Just run both programs, and connect to the ip address 127.0.0.1 with your client. And it will connect to the server running on your box.

127.0.0.1 is the home IP Address, which works on any box.

Try that out.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding multiple IPs to network adapter in C++ aalfabob C and C++ 0 04-17-2008 11:47 PM
Windows Shortcut List - Saves Time 2stamlers The Lounge 6 04-10-2008 06:58 AM
Delphi network help! janevblagoj Pascal/Delphi 0 02-24-2008 12:01 PM
Windows XP Tricks & Tips!!!!..new ones. pranky Tutorials, Classes and Code 7 02-01-2007 10:58 PM
Introducing The PAD Service Shareware Network pad service Hosting and Registrars 2 05-16-2006 02:07 PM


All times are GMT -5. The time now is 10:05 AM.

Contest Stats

John ........ 203.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 63%

Ads