-3
#import <java.net.Socket>
#import <java.io.InputStream>
#import <java.io.OutputStream>

int main() {
 Socket socket = new Socket("localhost", 80);
  InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
   }

I can not get simple socket opened it gives a compiler errors

Alex
  • 3
  • 2

1 Answers1

0

Looks look you are trying to fuse C and Java.

Your example in pure Java:

import java.net.Socket;
import java.io.InputStream;
import java.io.OutputStream;

public class MyFirstSocket {
    public static void main(String[] args) {
        Socket socket = new Socket("localhost", 80);
        InputStream in = socket.getInputStream();
        OutputStream out = socket.getOutputStream();
    }
}

If you want to use sockets in C, see Simplest Way To Open and Use a Socket in C.

Community
  • 1
  • 1
rgajrawala
  • 2,148
  • 1
  • 22
  • 35
  • thanks after digging through c codes i don't want to learn it. i know its a newer language than java but it is very bad with naming. i can hardly understand whats going on with the weird names. i will stick with the older languages like java and javascript for now. – Alex Nov 06 '15 at 01:51
  • 2
    C is much older than java and javascript... In fact, I'm pretty sure original implementations of java and javascript are written in C (or at least parts of them) – DTSCode Nov 18 '15 at 20:10