Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 20-07-2008, 11:55 PM   #1 (permalink)
In The Zone
 
Join Date: Jul 2005
Location: Hyderabad
Posts: 231
Talking Best language for socket programming


i need to learn socket programming to build simple client/server application for linux and windows platforms please suggest a language whose learning curve is easy... i check for tuts on C and C++ and i found it pretty hard to follow i guess i will need help was planning to take up some classes and i also herd about Ruby which is a cross platform interpreted language and i herd there are not much hasssels when it comes down to socket programming...

i need to learn a language which will give me access to pretty low level stuff so that in futher i can develop more powerfull applications ..
__________________
fighting for peace is like ****ing for virginity
cryptid is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 21-07-2008, 08:36 AM   #2 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Best language for socket programming

You can try out Ruby or Python (Or the likes - PERL/PHP)

But by the looks of your question, you are shying away from actually learning things before you attempt to implement, this will not get you anywhere if true.

I have little idea about network programming but I've written a basic application performing the client/server process in Python. You can read the below to valuate if the abstraction provided by Python is enough for your needs or not. (I'm using the default socket module provided by Python)

The server snippet:
Code:
import socket

address, buff = ("localhost", 21000), 2048

Sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Sock.bind(address)

print "SERVER\n------\n"

while True:
    
    data, address = Sock.recvfrom(buff)
    if not data:
        print "Client stopped/exited."
        break
    else:
        print "Recieved the message:", data

Sock.close()
The Client snippet:
Code:
import socket

address = ("localhost", 21000)

Sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

print "CLIENT\n------\n"

while True:
    data = raw_input("Enter a message: ")
    if not data:
        Sock.sendto("", address)
        break
    else:
        if Sock.sendto(data, address):
            print "Sent message:", data, "to", address[0], "at port", address[1]
        else:
            print "Could not send the message. Retry."

Sock.close()
Input (Client side) [Example]:
Code:
CLIENT
------

Enter a message: hello
Sent message: hello to localhost at port 21000
Enter a message: world
Sent message: world to localhost at port 21000
Output (Server side) [Example]:
Code:
SERVER
------

Recieved the message: hello
Recieved the message: world
In Colleges they usually teach network programming in C/C++. You get more direct access to all the low-level stuff in those languages.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 21-07-2008, 07:14 PM   #3 (permalink)
In The Zone
 
Join Date: Jul 2005
Location: Hyderabad
Posts: 231
Default Re: Best language for socket programming

seems pretty nice.... the thing is that C/C++ network programming is not coverd in out engg syllabus anyways i've been reading up on a some ebooks i got my hands on so it make take me some more time to decide on which language i should be going with... mean while if u guys get anymore interesting finds let me know...
__________________
fighting for peace is like ****ing for virginity
cryptid is offline  
Old 21-07-2008, 07:39 PM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Best language for socket programming

What kind of interesting finds?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 21-07-2008, 10:27 PM   #5 (permalink)
Legen-wait for it-dary!
 
dheeraj_kumar's Avatar
 
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
Default Re: Best language for socket programming

I recommend WinSock for windows, and I'm not a penguin so dunno abt linux. WinSOck is not exactly easy to learn but its very flexible and powerful. You can go the WinAPI way or the highly abstracted .NET way.
__________________
If the Start Windows Restart when Windows starts check box is checked Windows Restart will start automatically every time Windows is started. - Actual excerpt from a windows program help file
dheeraj_kumar is offline  
Old 21-07-2008, 10:30 PM   #6 (permalink)
Wahahaha~!
 
Faun's Avatar
 
Join Date: Dec 2006
Location: Pune/there
Posts: 7,676
Default Re: Best language for socket programming

java is the way if u want to start with implementation without going beneath the abstraction.

I remember I wrote a threaded multi messenger on LAN using JAVA. It was fun, included some cool features too. but duh I always abandon my projects at 80% dunno but thats me or i set high standards
__________________
Blog | Flickr | Battlelog
Spoiler:
Asus Z68 V-Pro|i5 2500k|TRUE Black|Ripjaws X|U2311H|N560GTX|D7000|XONAR STX|RE272|RE0|CC51|XE200PRO Walnut| TD II V2| Ultraphile|N5800

Mono
Faun is offline  
Old 21-07-2008, 10:49 PM   #7 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default Re: Best language for socket programming

t159. you remind me of the saying the last 20% of the project takes up 80% of hte time. you just didn't have the patience to stick to it for the 80%. :-P. just a thought.
well c is good enough for network programming. but the thing is that if you want to learn network programming, you need to be comfortable in the language first, otherwise you will be verrrry confused. any language can be used imho.
__________________
Life is too short. Have fun.
ilugd is offline  
Old 21-07-2008, 11:15 PM   #8 (permalink)
Wahahaha~!
 
Faun's Avatar
 
Join Date: Dec 2006
Location: Pune/there
Posts: 7,676
Default Re: Best language for socket programming

^^I meant that for extra features that I wished to add But somehow never went back to add stars to complete that 20% . No one asked me to add those features and even the ones that i added. But it was me all the time working alone, though later on changed the stance to a lazy one.
__________________
Blog | Flickr | Battlelog
Spoiler:
Asus Z68 V-Pro|i5 2500k|TRUE Black|Ripjaws X|U2311H|N560GTX|D7000|XONAR STX|RE272|RE0|CC51|XE200PRO Walnut| TD II V2| Ultraphile|N5800

Mono
Faun is offline  
Old 21-07-2008, 11:57 PM   #9 (permalink)
Beware of the innocent
 
ilugd's Avatar
 
Join Date: Dec 2005
Posts: 1,024
Default Re: Best language for socket programming

^^ i have been there too. know what you are talking about.
__________________
Life is too short. Have fun.
ilugd is offline  
Old 22-07-2008, 12:32 AM   #10 (permalink)
CAFEBABE
 
chandru.in's Avatar
 
Join Date: Mar 2008
Location: Bangalore
Posts: 474
Thumbs up Re: Best language for socket programming

I'd go with T159's suggestion. Java is very simple and yet pretty powerful in handling TCP/IP and UDP sockets. No platform dependence (unlike Winsock or UNIX sockets) as it is pure TCP. Also, most network programming will need multi-threading and Java's multi-threading capabilities are first-class.

I'm not very comfortable with Python. But if I understand it right, a Java version of the server code given by QwertyManiac would be like this.
Code:
package demo;

import java.io.*;
import java.net.*;

public class SocketServer {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(21000);
            Socket connectedSocket = serverSocket.accept();

            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    connectedSocket.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println("Received the message: " + line);
            }
            System.out.println("Client stopped/exited");
        } catch (Exception e) {
            System.out.println("Communication Error!");
        }
    }
}
The client code would look like this.

Code:
package demo;

import java.io.*;
import java.net.*;

public class SocketClient {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost", 21000);
            PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    System.in));

            while (true) {
                System.out.print("Enter message: ");
                String message = reader.readLine();
                writer.println(message);
                System.out.println("Sent message: " + message + " to "
                        + socket.getRemoteSocketAddress() + " at port "
                        + socket.getPort());
            }
        } catch (Exception e) {
            System.out.println("Communication Error!");
        }
    }
}
__________________
Chandru

http://tuxychandru.blogspot.com

Last edited by chandru.in; 22-07-2008 at 12:51 AM.
chandru.in is offline  
Old 22-07-2008, 04:26 PM   #11 (permalink)
Tired of being sorry!
 
quad_master's Avatar
 
Join Date: Jan 2008
Location: City of Joy
Posts: 67
Default Re: Best language for socket programming

+1 for java also its a goooooood platform independent lang
__________________
There are 10 types of people in this world, those who understand binary and those who do not.
quad_master is offline  
Old 22-07-2008, 04:41 PM   #12 (permalink)
Think Zen.
 
ray|raven's Avatar
 
Join Date: Dec 2005
Posts: 1,498
Default Re: Best language for socket programming

^Yea , Use SWT for the GUI and you have urself native looking apps.
__________________
Do what you will; but not because you must. -- Zen Quote
ray|raven is offline  
Old 22-07-2008, 05:57 PM   #13 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Best language for socket programming

/me hates java on principle.

Learn the details in C/C++, then actually use it in python.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 22-07-2008, 06:04 PM   #14 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: Best language for socket programming

+1 more for Java...

BTW, whats SWT ray|raven ?? Do u mean AWT ?? And if it is AWT, then instead of that, use Swing which is more advanced !
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 22-07-2008, 06:48 PM   #15 (permalink)
CAFEBABE
 
chandru.in's Avatar
 
Join Date: Mar 2008
Location: Bangalore
Posts: 474
Default Re: Best language for socket programming

Quote:
Originally Posted by Garbage View Post
+1 more for Java...

BTW, whats SWT ray|raven ?? Do u mean AWT ?? And if it is AWT, then instead of that, use Swing which is more advanced !
SWT stands for Standard Widget Toolkit. It is more like a balance between AWT and Swing.

AWT - Fully peer based rendering.
Swing - Fully Java based rendering.
SWT - Peer based rendering when possible, if not uses Java based rendering.

It is a separate library and does not form part of the standard Java runtime. Eclipse is developed using SWT. There is one catch in using SWT. You need to create separate packages of your application for each platform with the corresponding platform's SWT implementation.

Swing's native look and feel is improving (not as perfect as SWT). It is also a Java spec standard and fully cross-platform. So unless perfect native look is of very high importance for the application, I'd recommend using Swing with the platform's native look and feel at runtime.

Anyway since the topic is about socket programming only, I dunno the exact GUI requirements of the OP.

Quote:
Originally Posted by Sykora View Post
/me hates java on principle.

Learn the details in C/C++, then actually use it in python.
For TCP/IP and UDP, i don't see Java hiding any important detail. But if you want to use UNIX sockets or Winsock C/C++ is the way to go. But then TCP/IP is pretty much standardised for modern network programming.

That said Qt (QSocket) does a good job at abstracting TCP/IP stack for C++. I dunno about GTK so can't comment on that.
__________________
Chandru

http://tuxychandru.blogspot.com

Last edited by chandru.in; 22-07-2008 at 07:01 PM. Reason: Automerged Doublepost
chandru.in is offline  
Old 22-07-2008, 07:32 PM   #16 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Best language for socket programming

Oh noes, its turning into a language war!

Best way: Learn everything, program in anything.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 22-07-2008, 07:37 PM   #17 (permalink)
CAFEBABE
 
chandru.in's Avatar
 
Join Date: Mar 2008
Location: Bangalore
Posts: 474
Default Re: Best language for socket programming

Quote:
Originally Posted by QwertyManiac View Post
Oh noes, its turning into a language war!

Best way: Learn everything, program in anything.
Ooops!! No never meant to turn it into one. I still feel it is just a healthy debate of pros and cons. I love all languages discussed here so far (though I'm not very comfortable with Python).

If I'm a reason for this to turn into a useless war, I'm sorry.
__________________
Chandru

http://tuxychandru.blogspot.com
chandru.in is offline  
Old 22-07-2008, 07:46 PM   #18 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: Best language for socket programming

Thanks Chandru.in for clearing...
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 22-07-2008, 07:58 PM   #19 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Best language for socket programming

Quote:
Originally Posted by QwertyManiac View Post
Best way: Learn everything, program in anything.
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 22-07-2008, 08:07 PM   #20 (permalink)
Wahahaha~!
 
Faun's Avatar
 
Join Date: Dec 2006
Location: Pune/there
Posts: 7,676
Default Re: Best language for socket programming

^^
may be you need comments and documentation too, so the other developer know the sh!t you meant and wrote
__________________
Blog | Flickr | Battlelog
Spoiler:
Asus Z68 V-Pro|i5 2500k|TRUE Black|Ripjaws X|U2311H|N560GTX|D7000|XONAR STX|RE272|RE0|CC51|XE200PRO Walnut| TD II V2| Ultraphile|N5800

Mono
Faun is offline  
Old 22-07-2008, 09:22 PM   #21 (permalink)
In The Zone
 
Join Date: Jul 2005
Location: Hyderabad
Posts: 231
Default Re: Best language for socket programming

alright i think i will go the c/C++ way so please suggest some good books winsock programming.... i am currently reading Linux socket programming by example looks pretty decent so far i am able to understand the programs but was unable to compile it under my Ubuntu 8.04 with gcc 4

please take a looks at it

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
int
main(int argc,char **argv) {
int z; /* Status return code */
int s[2]; /* Pair of sockets */
/*
* Create a pair of local sockets:
*/
z = socketpair(AF_LOCAL,SOCK_STREAM,0,s);
if ( z == -1 ) {
fprintf(stderr,
“%s: socketpair(AF_LOCAL,SOCK_STREAM,0)\n”,
strerror(errno));
return 1; /* Failed */
}
/*
* Report the socket file descriptors returned:
*/
printf(“s[0] = %d;\n”,s[0]);
printf(“s[1] = %d;\n”,s[1]);
system(“netstat --unix -p”);
return 0;
}



the error returned is ...


cryptid@black-box:~/Socket_sandbox$ gcc -o pro 01LST01.c
01LST01.c: In function ‘main’:
01LST01.c:13: error: stray ‘\342’ in program
01LST01.c:13: error: stray ‘\200’ in program
01LST01.c:13: error: stray ‘\234’ in program
01LST01.c:13: error: expected expression before ‘%’ token
01LST01.c:13: error: stray ‘\’ in program
01LST01.c:13: error: stray ‘\342’ in program
01LST01.c:13: error: stray ‘\200’ in program
01LST01.c:13: error: stray ‘\235’ in program
01LST01.c:16: error: stray ‘\342’ in program
01LST01.c:16: error: stray ‘\200’ in program
01LST01.c:16: error: stray ‘\234’ in program
01LST01.c:16: error: expected expression before ‘%’ token
01LST01.c:16: error: stray ‘\’ in program
01LST01.c:16: error: stray ‘\342’ in program
01LST01.c:16: error: stray ‘\200’ in program
01LST01.c:16: error: stray ‘\235’ in program
01LST01.c:17: error: stray ‘\342’ in program
01LST01.c:17: error: stray ‘\200’ in program
01LST01.c:17: error: stray ‘\234’ in program
01LST01.c:17: error: expected expression before ‘%’ token
01LST01.c:17: error: stray ‘\’ in program
01LST01.c:17: error: stray ‘\342’ in program
01LST01.c:17: error: stray ‘\200’ in program
01LST01.c:17: error: stray ‘\235’ in program
__________________
fighting for peace is like ****ing for virginity
cryptid is offline  
Old 22-07-2008, 09:53 PM   #22 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Best language for socket programming

Well it's happening cos you did C-c C-v. Look at the ""
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 22-07-2008, 10:00 PM   #23 (permalink)
Wahahaha~!
 
Faun's Avatar
 
Join Date: Dec 2006
Location: Pune/there
Posts: 7,676
Default Re: Best language for socket programming

its the "quotes and ticks" problem which happens while copying from ebooks
lolz...noob
__________________
Blog | Flickr | Battlelog
Spoiler:
Asus Z68 V-Pro|i5 2500k|TRUE Black|Ripjaws X|U2311H|N560GTX|D7000|XONAR STX|RE272|RE0|CC51|XE200PRO Walnut| TD II V2| Ultraphile|N5800

Mono
Faun is offline  
Old 22-07-2008, 10:05 PM   #24 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Best language for socket programming

No, it isn't ticks.
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 22-07-2008, 10:15 PM   #25 (permalink)
Wahahaha~!
 
Faun's Avatar
 
Join Date: Dec 2006
Location: Pune/there
Posts: 7,676
Default Re: Best language for socket programming

^^you sure its not double quotes ?

"quotes and ticks is a general name to this problem coined by neo darwin"
lolz
__________________
Blog | Flickr | Battlelog
Spoiler:
Asus Z68 V-Pro|i5 2500k|TRUE Black|Ripjaws X|U2311H|N560GTX|D7000|XONAR STX|RE272|RE0|CC51|XE200PRO Walnut| TD II V2| Ultraphile|N5800

Mono

Last edited by Faun; 22-07-2008 at 10:19 PM. Reason: Automerged Doublepost
Faun is offline  
Old 23-07-2008, 07:17 AM   #26 (permalink)
Think Zen.
 
ray|raven's Avatar
 
Join Date: Dec 2005
Posts: 1,498
Default Re: Best language for socket programming

Quote:
Originally Posted by QwertyManiac View Post
Oh noes, its turning into a language war!
Die QwertyM for starting a language war

Quote:
Originally Posted by Garbage View Post
+1 more for Java...

BTW, whats SWT ray|raven ?? Do u mean AWT ?? And if it is AWT, then instead of that, use Swing which is more advanced !
Like Chandru.in said , its another gui toolkit for Java.
The advantage over Swing is that , SWT lets the native system draw the widgets , so they're faster than swing widgets , and the look-n-feel is consistent. It also takes away some load from the JVM i guess.

The disadvantage is that , you gotta compile each platform's version with a compatible version of SWT.
__________________
Do what you will; but not because you must. -- Zen Quote

Last edited by ray|raven; 23-07-2008 at 07:20 AM. Reason: Automerged Doublepost
ray|raven is offline  
Old 23-07-2008, 09:44 PM   #27 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Best language for socket programming

I never said a word against any language, and I gave an example in the one I could
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Closed Thread

Bookmarks

Thread Tools
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
Which Programming Language i should use? Thegame Programming 4 16-02-2008 11:47 AM
Best Programming Language nepcker Programming 8 23-05-2007 07:25 PM
Knowing more than one programming language rajesh_nk22 Programming 1 23-05-2007 02:09 PM
In which programming language? manas Programming 2 27-05-2006 05:37 PM
[help] Socket programming in unix enigmatic Open Source 7 05-07-2005 10:01 PM

 
Latest Threads
- by Sujeet
- by clmlbx
- by Sujeet
- by icebags

Advertisement




All times are GMT +5.5. The time now is 11:06 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2