serversocket

java socket: listen before accept?

自古美人都是妖i 提交于 2019-12-08 00:38:33
问题 The context: I have a table of banned ip adresses, due to DOS attacks, in a collection somewhere in the memory of my program. I use a TCP server socket, accepting every connection, then I check the ip address, and then I either close the connection or continue processing the client. I'd like to know if it's possible, in Java, to listen for incomming connections on a TCP server socket, and accept or refuse somehow to establish the tcp link, given the ip address of the requesting client. I mean

Netty ByteToMessageDecoder can't be @sharable

China☆狼群 提交于 2019-12-08 00:08:27
问题 I use MyDecoder which extends ByteToMessageDecoder to get Message from the socket Stream. It works fine in one thread. But in more threads, the netty has reported 'the handler should be sharable' However, I search in netty api, the ByteToMessageDecoder can't be @sharable, so how can I use it in multi thread. 回答1: Create a new instance in your ChannelInitializer. 来源: https://stackoverflow.com/questions/26559829/netty-bytetomessagedecoder-cant-be-sharable

Java Socket/Serversocket WAN Connection

大城市里の小女人 提交于 2019-12-07 07:30:36
问题 Im trying to make a server out of my computer so that clients from their computers can connect and communicate with my computer. I made the server on port 31350 and the client is trying to connect through my router's ip address. But it only works through lan when I have "localhost" or the name of my computer in the parameters for the socket creation. and not when I use my ip address, running the client and server on different networks. Here is the code. Here is the server that my computer is

Server socket - accept connections only from IP addresses in the whitelist

心不动则不痛 提交于 2019-12-07 02:15:31
I have a socket server that listens and accepts connections from client, which works as follow: ... do some pre-processing (socket, binds, etc) //listen to client if (listen(sockfd, BACKLOG) == -1) { perror("listen"); exit(1); } printf("server: waiting for connections...\n"); while(1) { // main accept() loop sin_size = sizeof client_addr; new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size); if (new_fd == -1) { perror("accept"); continue; } //do something ..... ..... } How can I restrict the server so it only accepts connection from specific IP addresses? For instance, I can

ServerSocket Android

孤街浪徒 提交于 2019-12-06 17:09:22
问题 Hey community I have the following ServerSocket which should listen to port 53000 and log any received data. However, I cannot seem to get past the server.accept() blocking call. public void run() { SocketServer server = new ServerSocket(53000); //---buffer store for the stream--- byte[] buffer = new byte[1024]; //---bytes returned from read()--- int bytes; //---keep listening to the InputStream until an // exception occurs--- while (true) { try { socket = server.accept(); BufferedReader in =

Socket Backlog behaviour

血红的双手。 提交于 2019-12-06 14:41:56
In case of a Serversocket have full of request in its backlog and doing a long running job what will be the socket behaviour. When I try this, from windows telnet is ok, it connects. But from unix it gets "connection refused" . My application is written in java and running on IBM jvm . By the way I came to that point where our application was not responding telnet from unix. Not respoing means it was writing "tyring..." and hangs, not refusing or connecting. Can anybody justify this behavior? Thank you. You should not get "Connection refused", if the socket is in LISTEN state. Until you

How do I Send Data to All Threaded Clients in Java?

ぐ巨炮叔叔 提交于 2019-12-06 13:10:42
问题 I am fairly new to Java, and I am trying to construct a very basic Java Relay server that sends messages from clients to all connected clients. I have figured out how to do threading to allow multiple connections, but I am having trouble figuring out how to echo an incoming message to ALL connected socket threads. Here is my Main.java source: http://pastebin.com/vVewfv3s Here is my SocketThread.java source: http://pastebin.com/yHA2BcUi Basically, I want to know the easiest way with my current

Java - connection to ServerSocket via browser/URL

烂漫一生 提交于 2019-12-06 12:46:19
I'm writing a piece of software, and I'm under the restriction of not being able to use socket to connect to a java application using a ServerSocket. I thought I'd try with an URL connection, since it's possible to define which port to connect to e.g: 127.0.0.1:62666 I have my server app listening for connections and writing the input out to a jTextArea. When connecting to the server (127.0.0.1:62666) through a browser, it outputs: GET / HTTP/1.1 GET /favicon.ico HTTP/1.1 I have another app for connecting to the ServerSocket through an URL connection: try{ URL url = new URL("http://127.0.0.1

Java Socket编程(理论)

丶灬走出姿态 提交于 2019-12-06 11:02:41
socket chat: http://www.cn-java.com/download/data/book/socket_chat.pdf 一、网络编程中的两个问题: 1.找到指定主机:IP层负责网络主机的定位; 2.可靠高效的传输数据:TCP层提供面向应用的可靠(TCP)和非可靠(UDP)的数据传输机制。 二、目前流行的网络编程模式: 客户端/服务器(C/S)模式。 在C/S模式中,通信一方作为服务器,等待客户端提出请求并予以响应。(服务器端通常作为守护进程,始终运行,监听网络端口,随时作出响应);通信另一方作为客户端,在需要服务时向服务器发出请求。 三、两类传输协议:TCP和UDP TCP ( Tranfer Control Protocol) ,是一种面向连接的保证 可靠传输的协议 。通过 TCP 协议传输,得到的是一个 顺序的无差错的数据流 。发送方和接收方的成对的两个 socket 之间必须建 立连接,以便在 TCP 协议的基础上进行通信,当一个 socket (通常都是 server socket )等待建立连接时,另一个 socket 可以要求进行连接,一旦这两个 socket 连接起来,它们就可以进行双向数据传输,双方都可以进行发送 或接收操作。 UDP ( User Datagram Protocol ),是一种 无连接的协议 ,每个数据报都是一个独立的信息

java socket: listen before accept?

假装没事ソ 提交于 2019-12-06 07:25:16
The context: I have a table of banned ip adresses, due to DOS attacks, in a collection somewhere in the memory of my program. I use a TCP server socket, accepting every connection, then I check the ip address, and then I either close the connection or continue processing the client. I'd like to know if it's possible, in Java, to listen for incomming connections on a TCP server socket, and accept or refuse somehow to establish the tcp link, given the ip address of the requesting client. I mean without having to accept & to close the client socket, which is what I'm already doing. Thanks.